How to convert 2d into 3D image - OpenCV Q&A Forum

Created
Tags
URLhttps://answers.opencv.org/question/50522/how-to-convert-2d-into-3d-image/

Attention! This forum will be made read-only by Dec-20. Please migrate to . Most of existing active users should've received invitation by e-mail.

How to convert 2d into 3D image

asked Nov 11 '14

arya1 ●1 ●1

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

Comments

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

ManyToLearn (Apr 11 '19)

add a comment

2 answers

Sort by »oldestnewestmost voted

0

answered Feb 4 '15

AJW81 ●1 ●5

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.

link

add a comment

0

answered Nov 11 '14

dtmoodie106 ●1 ●4

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

link

Comments

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

arya (Nov 25 '14)

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 (Feb 4 '15)

add a comment

Login/Signup to Answer