Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using solvePnPRansac function

I'm using Python 2.7 and opencv 3.0.0. I'm trying to do a pose estimation on a live video. So i used the calibrate.py gave by opencv. it works good. In this program, I added at the end lines to treat the informations in order to pose axis. I used this : http://docs.opencv.org/master/d7/d53/tutorial_py_pose.html#gsc.tab=0

On the line with solvePnPRansac function I wrote this instead : _, rvecs, tvecs, inliers = cv2.solvePnPRansac(obj_points[0], corners2, camera_matrix, dist_coefs) adding the _,at the beginning of the line.

I have this error appearing !

error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\matrix.cpp:2294: error: (-215) d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) in function cv::_OutputArray::create

I don't understand it at all !

Can someone help me ?

Here is my code to treat the video :

cap = cv2.VideoCapture(0)

while(1):


    # Take each frame
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

    # Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray, (6,5),None)

    if ret:

        term = ( cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 30, 0.1 )

        corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),term)


        _, rvecs, tvecs, inliers = cv2.solvePnPRansac(obj_points[0], corners2, camera_matrix, dist_coefs)

        imgpts, jac = cv2.projectPoints(axis, rvecs, tvecs, camera_matrix, dist_coefs)


        frame = draw(frame,corners2,imgpts)

    cv2.imshow('img',frame)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break
cap.release()
cv2.destroyAllWindows()
like image 223
Baptiste Valadié Avatar asked Oct 30 '22 15:10

Baptiste Valadié


1 Answers

I had the same problem. I used solvePnP instead of solvePnPRansac and it worked fine. I guess solvePnPRansac in python has a bug.

like image 140
ilan grinberg Avatar answered Nov 15 '22 03:11

ilan grinberg