OpenCV:solvePnP tvec单位和轴方向 [英] OpenCV: solvePnP tvec units and axes directions

查看:705
本文介绍了OpenCV:solvePnP tvec单位和轴方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找相机与棋board的相对位置(或者反之)-我可以在不同的坐标系之间进行转换,例如根据建议此处.由于可以使用findChessboardCorners来获取imagePoints(因此可以正常工作),因此我决定在这一阶段不仅使用棋盘进行校准,而且还用于确定实际位置.

I'm trying to find the relative position of the camera to the chessboard (or the other way around) - I feel OK with converting between different coordinate systems, e.g. as suggested here. I decided to use chessboard not only for calibration but actual position determination as well at this stage, since I can use the findChessboardCorners to get the imagePoints (and this works OK).

我已经阅读了很多有关该主题的文章,并且觉得我理解solvePnP输出(即使我对openCV和计算机视觉完全陌生).不幸的是,我从solvePnP获得的结果和在物理上测量测试设置的结果是不同的:z方向的平移大约为. 25%. xy方向是完全错误的-与我读过的相机坐标系(x指向图像,y指向右侧,z远离相机)相比,几个数量级和不同的方向.如果将tvecrvec转换为世界坐标系中的相机姿态,差异仍然存在.

I've read a lot on this topic and feel that I understand the solvePnP outputs (even though I'm completely new to openCV and computer vision in general). Unfortunately, the results I get from solvePnP and physically measuring the test set-up are different: translation in z-direction is off by approx. 25%. x and y directions are completely wrong - several orders of magnitude and different direction than what I've read to be the camera coordinate system (x pointing up the image, y to the right, z away from the camera). The difference persists if I convert tvec and rvec to camera pose in world coordinates.

我的问题是:

  • 相机和世界坐标系的轴的方向是什么?
  • solvePnP是否以与我指定的objectPoints相同的单位输出翻译?
  • 我将世界原点指定为objectPoints的第一个(棋盘角之一).可以吗?tvec是从摄像机坐标精确地转换到该点吗?
  • What are the directions of camera and world coordinate systems' axes?
  • Does solvePnP output the translation in the same units as I specify the objectPoints?
  • I specified the world origin as the first of the objectPoints (one of the chessboard corners). Is that OK and is tvec the translation to exactly that point from the camera coordinates?

这是我的代码(我将其附加为形式,因为它不会引发任何异常等).我在校准过程中使用了灰度图像来获取相机的本征矩阵和失真系数,因此决定也要在灰度中进行定位. chessCoordinates是相对于原点(角点之一)以毫米为单位的棋of点位置的列表. camMatrixdistCoefficients来自校准(使用相同的棋盘和objectPoints执行).

This is my code (I attach it pro forma as it does not throw any exceptions etc.). I used grayscale images to get the camera intrinsics matrix and distortion coefficients during calibration so decided to perform localisation in grayscale as well. chessCoordinates is a list of chessboard points location in mm with respect to the origin (one of the corner points). camMatrix and distCoefficients come from calibration (performed using the same chessboard and objectPoints).

camCapture=cv2.VideoCapture(0) # Take a picture of the target to get the imagePoints 
tempImg=camCapture.read()
imgPts=[]
tgtPts=[]

tempImg=cv2.cvtColor(tempImg[1], cv2.COLOR_BGR2GRAY)
found_all, corners = cv2.findChessboardCorners(tempImg, chessboardDim )

imgPts.append(corners.reshape(-1, 2))
tgtPts.append(np.array(chessCoordinates, dtype=np.float32))

retval,myRvec,myTvec=cv2.solvePnP(objectPoints=np.array(tgtPts), imagePoints=np.array(imgPts), cameraMatrix=camMatrix, distCoeffs=distCoefficients)

推荐答案

相机坐标与图像坐标相同.因此,x轴指向相机的右侧,y轴指向下方,z指向相机的朝向.这是一个顺时针的斧头系统,同样适用于棋盘,因此,如果您在棋盘的右上角指定了原点,则x斧头沿棋盘的右端较长,而y则沿棋盘短边.棋盘z轴将指向下方,指向地面.

The camera coordinates are the same as image coordinates. So You have x axe pointing in the right side from the camera, y axe pointing down, and z pointing in the direction camera is faced. This is a clockwise axe system, and the same would apply to the chessboard, so if You specified the origin in, lets say, upper right corner of the chessboard, x axe goes along the longer side to the right and y along shorter side of the chessboard, z axe would be pointing downward, to the ground.

Solve PnP以与您指定棋board字段长度的单位相同的单位输出转换,但是由于它使用相机矩阵,因此它也可能会使用相机校准中指定的单位.

Solve PnP outputs the translation in the same units as the units in which You specified the length of chessboard fields, but it might also use units specified in camera calibration, as it uses the camera matrix.

Tvec指向放置校准对象的世界坐标的原点.因此,如果将第一个对象指向(0,0),则tvec将指向该对象.

Tvec points to the origin of the world coordinates in which You placed the calibration object. So if You placed the first object point in (0,0), thats where tvec will point to.

这篇关于OpenCV:solvePnP tvec单位和轴方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆