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 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!