Python 使用opencv的相机暂停功能产生意外结果

Python 使用opencv的相机暂停功能产生意外结果,python,image,opencv,camera,calibration,Python,Image,Opencv,Camera,Calibration,我将Opencv与python 2.7一起使用 我用棋盘获得了相机的内在矩阵和相机暂停的外在矩阵: (ret, mtx, dist, rvecs, tvecs) = cv2.calibrateCamera(objpoints, imgpoints, grayImg.shape[::-1],None,None) [ret, rvec, tvec] = cv2.solvePnP(objp, corners, mtx, distCoeff) 然后,我使用cv.projectPoints在图像中绘制

我将Opencv与python 2.7一起使用

我用棋盘获得了相机的内在矩阵和相机暂停的外在矩阵:

(ret, mtx, dist, rvecs, tvecs) = cv2.calibrateCamera(objpoints, imgpoints, grayImg.shape[::-1],None,None)

[ret, rvec, tvec] = cv2.solvePnP(objp, corners, mtx, distCoeff)
然后,我使用cv.projectPoints在图像中绘制了世界坐标轴

 axes = chess_board_square_sz * np.float32([[1,0,0], [0,1,0], [0,0,-1]]).reshape(-1,3)
[axes_proj,  jac] = cv2.projectPoints(axes, rvec, tvec, mtx, distCoeff)
img = draw_axes(img, corners2, axes_coor)    
到目前为止,一切正常:世界坐标轴以3d形式出现在图像上,原点位于棋盘的一角,两个坐标轴平行于棋盘的侧面,第三个坐标轴稍后与之正交

我还将rvec向量转换为旋转矩阵:

Rmat = cv2.Rodrigues(rvec)[0] #rotation matrix of the camera pause
现在,我想将摄像机轴在图像上的投影可视化;更精确地说,我想绘制点的投影,这些点在摄影机轴系统中的坐标为[1,0,1]、[0,1,1]和[0,0,1]

通常:我应该观察一个直角三角形,它的两个正交边平行于图像的边,因为相机坐标轴是这样定义的

根据我读到的所有内容,世界坐标和摄像机坐标由X_-cam=Rmat*X_-world+tvec关联,因此X_-world=Rmat^-1 X_-cam-tvec。因此,下面的代码应该显示一个直角三角形,角可能位于图像中心附近:

cam_axes = chess_board_square_sz * np.float32([1,0,1], [0,1,1], [0,0,1]);
world_cam_axes = n.dot(Rmat.T, (cam_axes - tvec))  
[proj_cam_axes, jac] = cv2.projectPoints(world_cam_axes, rvec, tvec, mtx, dist)

img = cv2.imread(calibr_img_name)
img = cv2.line(img, tuple(rproj_cam_axes[0].ravel(), tuple(rproj_cam_axes[1].ravel()), [255,0,0], 5)
img = cv2.line(img, tuple(rproj_cam_axes[0].ravel(), tuple(rproj_cam_axes[2].ravel()), [0,255,0], 5)
img = cv2.line(img, tuple(rproj_cam_axes[1].ravel(), tuple(rproj_cam_axes[2].ravel()), [0,0,255], 5)
fig, ax2 = plt.subplot(1)
ax2.imshow(img2, interpolation = 'bicubic')
但图像上显示的内容与直角三角形非常不同,即使三角形的一个角靠近图像的中心。
有人能解释一下这里发生了什么吗?

这只是cv.projectPoints的输入参数问题:这应该是

[proj_cam_轴,jac]=cv2.projectPointsworld_cam_轴T、rvec、tvec、mtx、Discoefs

为了将world_cam_轴矩阵转换为opencv文字中的对象点