为了账号安全,请及时绑定邮箱和手机立即绑定

我正在尝试使用 cv2.projectPoints() 但出现错误

我正在尝试使用 cv2.projectPoints() 但出现错误

德玛西亚99 2023-06-27 14:33:30
这是错误:imgpts, jac = cv2.projectPoints(axis, rvecs, tvecs, mtx, dist)cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\calib3d\src\calibration.cpp:603: error: (-5:Bad argument) Rotation must be represented by 1x3 or 3x1 floating-point rotation vector, or 3x3 rotation matrix in function 'cvProjectPoints2Internal'这是我的代码:axis = np.float32([[3, 0, 0], [0, 10, 0], [0, 0, -50]]).reshape(-1, 3)#axis of coordinates# PnP calculates the rotation vector and translation vectorrvecs, tvecs, inliers = cv2.solvePnP(obj_points, image_points, mtx, dist)print(f"mtx shape: {mtx.shape}, tvecs shape: {tvecs.shape}")print(f"mtx:\n {mtx}")print(f"tvecs:\n {tvecs}")# Calculate the coordinates of 3D points projected on 2D image planeimgpts, jac = cv2.projectPoints(axis, rvecs, tvecs, mtx, dist)这是输出:mtx shape: (3, 3), tvecs shape: (3, 1)mtx: [[1.71223579e+03 0.00000000e+00 1.02990683e+03] [ 0.00000000e+00 1.70818827e+03 7.83446773e+02] [ 0.00000000e+00 0.00000000e+00 1.00000000e+00]]tvecs: [[-0.09038089] [ -0.05386737] [ -0.01652085]]我不知道如何解决它。问题似乎出在论证的形式上。但当我检查时,它们的形状似乎正确。所以我不知道问题是什么,但如果你这样做的话会非常有帮助。
查看完整描述

2 回答

?
慕哥9229398

TA贡献1877条经验 获得超6个赞

也许您正在尝试从旧教程中获取一些代码,或者您误读了有关返回值的函数文档。尝试像这样分配从solvePnP返回的值:

result, rvecs, tvecs = cv2.solvePnP(obj_points, image_points, mtx, dist)

solvePnP 函数中不应该有“内点”(至少从 opencv4 开始)。


查看完整回答
反对 回复 2023-06-27
?
慕容森

TA贡献1853条经验 获得超18个赞

尝试这个:

imagePoints, jacobian = cv.projectPoints(np.array(obj_points),
                        np.float32(rvec), np.float32(tvec),camera_matrix1, None)

组件的形状确实很重要,它对我有用。


查看完整回答
反对 回复 2023-06-27
  • 2 回答
  • 0 关注
  • 231 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信