Ask Your Question
0

OpenCV Error: Assertion failed in undistort.cpp at line 293 [closed]

asked 2017-05-18 02:12:48 -0600

djkpA gravatar image

updated 2017-05-18 02:24:48 -0600

OpenCV Error:

Assertion failed (CV_IS_MAT(_src) && CV_IS_MAT(_dst) && (_src->rows == 1 || _src->cols == 1) && (_dst->rows == 1 || _dst->cols == 1) && _src->cols + _src->rows - 1 == _dst->rows + _dst->cols - 1 && (CV_MAT_TYPE(_src->type) == CV_32FC2 || CV_MAT_TYPE(_src->type) == CV_64FC2) && (CV_MAT_TYPE(_dst->type) == CV_32FC2 || CV_MAT_TYPE(_dst->type) == CV_64FC2)) in cvUndistortPoints, file /home/javvaji/opencv-3.2.0/modules/imgproc/src/undistort.cpp, line 293

retval, rvec, tvec = cv2.solvePnP(cam.object_points, cam.image_points, cam.camera_matrix, cam.dist_coefficients, None, None, False, cv2.SOLVEPNP_P3P)

Parameter values: (all are numpy arrays)

 Image points: 
[[ 433.   50.]
 [ 512.  109.]
 [ 425.  109.]
 [ 362.  106.]]
Object points: 
[[ 0.   0.   0. ]
 [ 6.5  0.   0. ]
 [ 0.   0.   6.5]
 [ 0.   6.5  0. ]]
Cam mat:
[[ 811.13275146    0.          322.47589111]
 [   0.          811.27490234  225.78684998]
 [   0.            0.            1.        ]]
Dist Coff:
[[-0.07649349 -0.02313312 -0.00911118 -0.0049251   0.74063563]]

I am using solvePnP function with flag SOLVEPNP_P3P. It is giving assertion error. The same solvePnP code works fine with SOLVEPNP_ITERATIVE flag. With P3P flag it internally calls undistortPoints function which is giving error.

solvePnP code ref: https://github.com/opencv/opencv/blob...

How to resolve this?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-05-18 06:30:19.700210

Comments

1

I don't know python but in c++ your code is ok :

vector<Point2f> p2 = { Point2f(433,50),Point2f(512,109),Point2f(425,109),Point2f(362,106) };
vector<Point3f> p3 = { Point3f(0,0,0),Point3f(6.5,0,0),Point3f(0,0,6.5),Point3f(0,6.5,0) };
Mat rvec,tvec;
Mat c=(Mat_<double>(3,3)<< 811.13275146,0.,322.47589111, 0.,811.27490234,225.78684998,0., 0.,1.);
Mat d=(Mat_<double>(5,1)<< -0.07649349,-0.02313312 ,-0.00911118, -0.0049251 ,  0.74063563);
solvePnP(p3,p2,c,d,rvec,tvec,true, SOLVEPNP_P3P);

I think problem is that you need a mat with two channels. may be you can find some help here

LBerger gravatar imageLBerger ( 2017-05-18 02:45:09 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-18 03:29:55 -0600

djkpA gravatar image

In solvePnP code link I mentioned in line 95 it is calling undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs); I think the error is from this call

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-18 02:12:48 -0600

Seen: 2,410 times

Last updated: May 18 '17