Ask Your Question
0

Get Q matrix.

asked 2015-01-09 01:53:24 -0600

rcarrasco gravatar image

updated 2015-01-09 06:17:07 -0600

Hi, I'm new in opencv and I want to get the XYZ of a pixel. I have a stereo camera calibrated and I read that to obtain 3D coordinates used reprojectImageTo3D function, but I'm not sure how to get the parameter Q and disparity.

reprojectImageTo3D(InputArray disparity, OutputArray _3dImage, InputArray Q, bool handleMissingValues=false, int ddepth=-1 )

To get Q matrix, should I use stereoRectify function or is there another method?

UPDATE:

I try the next code to get the Q matrix:

#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
 cv::Mat R1;
 cv::Mat R2;
 cv::Mat P1;
 cv::Mat P2;
 cv::Mat Q;
 CvSize imageSize;
 Rect* validPixROI1=0;
 Rect* validPixROI2=0;
 imageSize.width = 640;
 imageSize.height = 480;

 float cam_matR[9] = {680.6194505553137, 0.0, 355.46071062373017, 0.0, 708.4327407870684, 166.020861837664, 0.0, 0.0, 1.0};
 float cam_matL[9] = {1443.36997726192, 0.0, 310.098678757853, 0.0, 1526.48462097625, -31.0051090142091, 0.0, 0.0, 1.0};
 float dist_cefR[9] = {-0.539747915499244, 0.40294694145911397, -0.014712916213760259, -0.035996511261222594, 0.0}; 
 float dist_cefL[9] = {-0.219030634019159, 0.607086354732134, -0.0559437412413443, 0.0274216517856112, 0.0};
 float _R[9] = {4347.70749725124, 0.0, 559.7353515625,0.0, 4347.70749725124, 134.066455841064,0.0, 0.0, 1.0};
 float _T[3] = {0.0,0.0,0.0};

 const cv::Mat cameraMatrixR = cv::Mat(3,3,CV_64F,cam_matR);
 const cv::Mat cameraMatrixL = cv::Mat(3,3,CV_64F,cam_matL);

 const cv::Mat distCoeffR = cv::Mat(1,5,CV_64F,dist_cefR);
 const cv::Mat distCoeffL = cv::Mat(1,5,CV_64F,dist_cefL);

 const cv::Mat R = cv::Mat(3,3,CV_64F,_R);
 const cv::Mat T = cv::Mat(1,3,CV_64F,_T);

 stereoRectify(cameraMatrixR, distCoeffR, cameraMatrixL, distCoeffL, imageSize, R, T, R1, R2, P1, P2, Q, 0, -1, );
}

And I get the next error:

OpenCV Error: Assertion failed ((D.rows == ((flags & CV_GEMM_A_T) == 0 ? A.rows : A.cols)) && (D.cols == ((flags & CV_GEMM_B_T) == 0 ? B.cols : B.rows)) && D.type() == A.type()) in cvGEMM, file /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20140819-1745/modules/core/src/matmul.cpp, line 3150
terminate called after throwing an instance of 'cv::Exception'
 what():  /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20140819-1745/modules/core/src/matmul.cpp:3150: error: (-215) (D.rows == ((flags & CV_GEMM_A_T) == 0 ? A.rows : A.cols)) && (D.cols == ((flags & CV_GEMM_B_T) == 0 ? B.cols : B.rows)) && D.type() == A.type() in function cvGEMM

Aborted (core dumped)
edit retag flag offensive close merge delete

Comments

berak gravatar imageberak ( 2015-01-09 07:40:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-14 03:33:32 -0600

PhantomFav gravatar image

You should declare the translate vector T as:

 const cv::Mat T = cv::Mat(3,1,CV_64F,_T);

This will prevent the assert to activate.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-01-09 01:53:24 -0600

Seen: 2,122 times

Last updated: Jan 09 '15