Ask Your Question
0

How to display output of reprojectImageTo3D ?

asked 2016-08-02 03:00:24 -0600

Nbb gravatar image

updated 2016-08-02 09:00:30 -0600

I am trying out a project on 3D reconstruction and I am doing fine until now. The output of reprojectImageTo3D is a 3D matrix where each element is a 3D coordinate. How do I display the 3D reconstructed scene ?

I am using 2.4.13. I read about viz3D but have yet to find any sample code. anyone help me please ?

edit retag flag offensive close merge delete

Comments

most easy way would be to write a ply or obj text file, and use an external viewer.

berak gravatar imageberak ( 2016-08-02 09:03:43 -0600 )edit

Thanks for the suggestion berak. How do I save the mat data as ply ? I cant find any samples. Would it be possible to do it using opencv functions ? Also, is it possible to visualize the point cloud using opencv function or is there no way to do it ?

Nbb gravatar imageNbb ( 2016-08-02 10:46:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-08-02 11:15:43 -0600

berak gravatar image

updated 2016-08-02 11:18:58 -0600

ply format is simple, just a header, followed by your 3d points:

ply
format ascii 1.0
element vertex <FILL_IN_NUMBER_OF_POINTS_HERE>
property float x
property float y
property float z
end_header
1 17 2.3
22 2 1
...

obj is even more simple, just put a 'v' in front of your x y z points:

v 1 4 2
v 2 2 2
v 17 2 1.3

again, your point cloud has only 'vertices', there is no mesh(triangles or such), which makes it quite simple in above cases.

if you compiled opencv with opengl support (WITH_OPENGL, check cv::getBuildInformation()), you can also try to use that:

void on_opengl(void* param)
{
        glLoadIdentity();
        glTranslated(0,0,-5); // -z points into screen !

        glPointSize(2.0);
        glBegin(GL_POINTS);
        for (int i = 0; i < numPoints; i++) {
            glColor3ub( 80, 30, 40 );
            glVertex3d(points[i][0], points[i][1], points[i][2]);
        }
        glEnd();   
}


String name = "ogl";
namedWindow(name, WINDOW_OPENGL);  
setOpenGlDrawCallback(name, on_opengl);
while (1)
{
     updateWindow(name); // this calls on_opengl
     int k = waitKey(20);
}

well, doh, if you're doing this for the 1st time, you'll end up with the model being behind your camera, being topdown and whatnot. it's an art of its own (and quite some time sink ..)

can't help you with viz3d at all. (been exposed to vtk 20 years ago, and have sworn never to touch that again ;)

edit flag offensive delete link more

Comments

Thanks berak. What if I am trying to view a plane ? I am working on stereo vision and Id like to be able to draw solid objects such as a plane on the 3d scene. Should I generate thousands of points for the object then use .obj viewer for it ? Also what simplest software would u recommend. I tried open3d model viewer but I am getting wrong. I only have

v 1 2 3 in my file I think open 3d viewer need f and other stuffs

Nbb gravatar imageNbb ( 2016-08-03 05:16:19 -0600 )edit
  • recent win comes with a builtin 3d viewer/modeler,
  • meshlab is nice and small.
  • if you want to draw/model, blender would be my favourite(despite it's non-intuitive gui...)

"Should I generate thousands of points for the object " -- yes, it somehow boils down to that..

then there are tools (e.g. in meshlab) to reduce the number of points again, and make triangles from that, etc.

berak gravatar imageberak ( 2016-08-03 05:30:39 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-08-02 03:00:24 -0600

Seen: 4,069 times

Last updated: Aug 02 '16