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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Point Cloud Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!