필터 지우기
필터 지우기

how to open a depth map from a file and transform it into a 3D point cloud - wanna convert c++ code to MATLAB script.

조회 수: 1 (최근 30일)
The following c++ code snippet show how to open a depth map from a file and transform it into a 3D point cloud:
FILE* inFile;
//read the file
fopen_s(&inFile,"depth.txt", "rb");
fread(d, sizeof(UINT16), nVertices, inFile);
fclose(inFile);
for(int i=0 ; i < nVertices ; i++)
{
int r_i = i / (int)n_c;
int c_i = i % (int)n_c;
//normalize depth
float d_i = (float)d[i] / (float)MAX_DEPTH;
//color
vertices[i].a = 255.;
//the color of the point is a shade of gray proportional to the depth
vertices[i].b = vertices[i].g = vertices[i].r = d_i;
//calculate x-coordinate
float alpha_h = (M_PI - theta_h) / 2;
float gamma_i_h = alpha_h + (float)c_i*(theta_h / n_c);
vertices[i].x = d_i / tan(gamma_i_h);
//calculate y-coordinate
float alpha_v = 2 * M_PI - (theta_v / 2);
float gamma_i_v = alpha_v + (float)r_i*(theta_v / n_r);
vertices[i].y = d_i * tan(gamma_i_v)*-1;
//z-coordinate
vertices[i].z = d_i;
}
So i wanna convert this to a MATLAB script.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by