Ask Your Question
0

How to convert 2d into 3D image

asked 2014-11-11 02:44:48 -0600

arya gravatar image

Now I am doing conversion of 2D images to 3D images. For that am using following steps.

(1). Input 2 images. (2). Detect keypoints using SIFT. (3). Extract Descriptors. (4). Compare and match descriptors. (5). find fundamental mat (findFundamentalMat()) from these pairs. (6). stereoRectifyUncalibrated(). (7). reprojectImageTo3D().

Now I want to know that what is this xyz and Q in reprojectImageTo3D? And what are the values given to xyz and to Q?

reprojectImageTo3D(imgDisparity8U, xyz, Q, true);

Because I got an error like this:

OpenCV Error: Assertion failed (Q.size() == Size(4,4)) in reprojectImageTo3D, file /home/arya/stuff/opencv/opencv-2.4.7/modules/calib3d/src/calibration.cpp, line 2823

edit retag flag offensive close merge delete

Comments

Hi, is it the steps are similar for 3d reconstruction process?

ManyToLearn gravatar imageManyToLearn ( 2019-04-11 06:27:53 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2015-02-04 03:06:45 -0600

AJW gravatar image

xyz is an output argument; after the function runs it will contain a 'vertex map', which is basically a matrix with 3 channels for each of the X,Y,Z coordinates of the 3D points you get back.

Your problem is with the Q matrix, also known as the reprojection matrix. To construct Q, you need to know the intrinsic parameters of your left camera (principal points and focal length) and possibly the principal point of the right camera. Unfortunately, without camera calibration you won't get these; you need to calibrate your cameras and run stereoRectify(), which will give you Q directly.

Technically, the error is occurring because reprojectImageTo3D() expects Q to be a 4x4 matrix, and whatever you gave it is not, but more generally, you can't produce Q with the information you have. I'd suggest reading the book 'Learning OpenCV' if you have access to it, it explains the relevant theory pretty well. There seem to be a few PDFs floating around on university course pages online, if you can't find it elsewhere.

edit flag offensive delete link more
0

answered 2014-11-11 09:24:15 -0600

dtmoodie gravatar image

I believe Q is either H1 or H2 from stereoRectifyUncalibrated depending on which frame imgDisparity8U is with respect to.

edit flag offensive delete link more

Comments

I tried H1 and H2 instead of Q. But it shows the same error.

arya gravatar imagearya ( 2014-11-25 03:11:46 -0600 )edit

I don't think that's correct. H1 and H2 are homography matrices that describe the warping required to rectify the left and right images respectively. Q is a matrix that can be used to project image points, along with their disparity value obtained from stereo matching, to 3D points

AJW gravatar imageAJW ( 2015-02-04 03:11:00 -0600 )edit

Question Tools

Stats

Asked: 2014-11-11 02:44:48 -0600

Seen: 5,862 times

Last updated: Nov 11 '14