2Dの映像を3Dにするためには。

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
ぬぬぬのぬ

2Dの映像を3Dにするためには。

#1

投稿記事 by ぬぬぬのぬ » 2年前

2Dの映像を3Dにするために、1つの絵ををoverとunderに分岐させ、分岐させたものをきかくかをとって3Dの1つの絵にするためには、以下のコードをどのように書けば教えてください。

コード:

__constant sampler_t samplerUnscaled = CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_FALSE;
__constant sampler_t samplerScaled = CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_FALSE;
#include "../../../shared/Interpolation_Kernels.cl"

#define NUMERIC_EPSILONF 0.000001f

#ifndef M_PI_2_F
#define M_PI_2_F 1.5707963267949f
#endif

__kernel void Equirectangular
<
略
>

( __read_only image2d_t Source, 
__write_only image2d_t Output, 
const float2 Center < label: "Center"; valueMin: -3.1415926535898f, -1.5707963267949f; valueMax: 3.1415926535898f, 1.5707963267949f; valueDefault: 0, 0; >,
const float Scale < label: "Scale"; valueMin: 0; valueMax: 4.0; valueDefault: 2.0; >,
const float ScalingHorizontal < label: "Horizontal"; group: "Scaling"; valueMin: 0.0; valueMax: 1.0; valueDefault: 1.0; >,
const float ScalingVertical < label: "Vertical"; group: "Scaling"; valueMin: 0.0; valueMax: 1.0; valueDefault: 1.0; >,
const int Is3D < label: "Is3D"; parameterType: Bool; valueDefault: 1; >,
//const int ForwardConv < label: "ForwardConv"; group: "Scaling"; parameterType: Bool; valueDefault: 1; >, // Not functional

const int width < valueFrom: imageWidth; >,
const int height < valueFrom: imageHeight; >
)
{
float nXDst = get_global_id(0);
float nYDst = get_global_id(1);

if(!Is3D)
{
float hwid = width * 0.5f;
float hhei = height * 0.5f;

float t_theta = -Center.x;
float t_phi = Center.y;

// Right-handed coordinate
float tx = native_cos(t_phi) * native_cos(t_theta);
float ty = native_sin(t_phi);
float tz = -native_cos(t_phi) * native_sin(t_theta);

float ux = native_sin(t_theta);
float uy = 0.0f;
float uz = native_cos(t_theta);

float vx = -native_sin(t_phi) * native_cos(t_theta);
float vy = native_cos(t_phi);
float vz = native_sin(t_phi) * native_sin(t_theta);

float dXSrc, dYSrc;

float dX = (nXDst - hwid) / width * Scale;
float dY = (nYDst - hhei) / width * Scale;

float px = tx + dX * ux + dY * vx;
float py = ty + dX * uy + dY * vy;
float pz = tz + dX * uz + dY * vz;

float pxz = native_sqrt(px * px + pz * pz);
float dThetaPi = -atan2pi(-pz, px);  // [-1.0, 1.0)
float dPhiPi = atan2pi(py, pxz);  // [-0.5, 0.5)

dXSrc = width * 0.5f * (1.0f + dThetaPi);
dYSrc = height * (0.5f + dPhiPi);
write_imagef(Output, (int2) (nXDst,nYDst), read_imagef_bilinear(Source, (float2)(dXSrc,dYSrc) ) );
} else { // process when input image is over/under sterctroscopic 3D 360
if (0 <= nYDst && nYDst <= height/2)
{
float dX = (nXDst - hwid) / width * Scale;
float dY = (nYDst - hhei/2) / width * Scale;

float tx = native_cos(t_phi) * native_cos(t_theta);
float ty = native_sin(t_phi);
float tz = -native_cos(t_phi) * native_sin(t_theta);

float ux = native_sin(t_theta);
float uy = 0.0f;
float uz = native_cos(t_theta);

float vx = -native_sin(t_phi) * native_cos(t_theta);
float vy = native_cos(t_phi);
float vz = native_sin(t_phi) * native_sin(t_theta);

float px = tx + dX * ux + dY * vx;
float py = ty + dX * uy + dY * vy;
float pz = tz + dX * uz + dY * vz;

float pxz = native_sqrt(px * px + pz * pz);  
float dThetaPi = -atan2pi(-pz, px);
// [-1.0, 1.0)
float dPhiPi = atan2pi(py, pxz);  // [0, 0.5)

dXSrc = width * 0.5f * (1.0f + dThetaPi);
dYSrc = height * (0.5f + dPhiPi);

}
else if (height/2 < nYDst && nYDst <= height) {
float dX = (nXDst - hwid) / width * scale;
float dY = (nYDst - hhei/2) / width * scale;

float tx = native_cos(t_phi) * native_cos(t_theta);
float ty = native_sin(t_phi);
float tz = -native_cos(t_phi) * native_sin(t_theta);

float ux = native_sin(t_theta);
float uy = 0.0f;
float uz = native_cos(t_theta);

float vx = -native_sin(t_phi) * native_cos(t_theta);
float vy = native_cos(t_phi);
float vz = native_sin(t_phi) * native_sin(t_theta);

float px = tx + dX * ux + dY * vx;
float py = ty + dX * uy + dY * vy;
float pz = tz + dX * uz + dY * vz;

float pxz = native_sqrt(px * px + pz * pz);
float dThetaPi = -atan2pi(-pz, px);
// 
float dPhiPi = atan2pi(py, pxz); 

dXSrc = width * 0.5f * (1.0f + dThetaPi);
dYSrc = height * (0.5f + dPhiPi);
}
write_imagef(Output, (int2) (nXDst,nYDst), read_imagef_bilinear(Source, (float2)(dXSrc,dYSrc) ) );
}
}

“C言語何でも質問掲示板” へ戻る