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() 2 Answers
Answers 1
solvePnpRansac has only three output values:
OutputArray rvec, OutputArray tvec, OutputArray inliers = noArray(), so removing the _, in the beginning should make the program work again.
Answers 2
You need to define obj_points the same manner in the example. I don't see obj_points definition in the provided code snippet and I think that's the issue
obj_points= np.zeros((6*7,3), np.float32) obj_points[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
0 comments:
Post a Comment