rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

huangapple go评论74阅读模式
英文:

Why are rvecs and tvecs different for every view in OpenCV's calibratecamera?

问题

我很难理解cv2.calibrateCamera输出中revecstvecs的真正含义。据我理解,它们共同定义了相机的姿态,即相机的位置和方向。

然而,如果我将从同一相机拍摄的多个视图传递给cv2.calibrateCamera,我会得到每个视图的rvecstvecs。如果相机没有移动,它们不应该是相同的吗?

我的第一张图像的单应矩阵定义如下:

K = mtx
R = cv2.Rodrigues(rvecs[0])[0]
T = tvecs[0]
RT = np.concatenate((R,T),axis=1)
H = np.dot(K, RT)

我可以看到它投影得很正确。按照我理解的单应性,如果相机没有移动,它应该对每个图像保持不变。但是如果R和T在变化,H也会变化。

看起来我可能漏掉了关于OpenCV中rvecstvecs定义方式的一些非常重要的东西。

英文:

I'm struggling to understand the real meaning of revecs and tvecs in the output of cv2.calibrateCamera. As I understand them, together they define the pose of the camera, meaning position and orientation of the camera.

However, if I pass multiple views shot from the same camera to cv2.calibrateCamera I get rvecs and tvecs for every view. Shouldn't they be the same if the camera didn't move?

My homography matrix for the first image is defined by

K = mtx
R = cv2.Rodrigues(rvecs[0])[0]
T = tvecs[0]
RT = np.concatenate((R,T),axis=1)
H = np.dot(K, RT)

And I can see that it projects correctly. The way I understand homography it should stay the same for every image as the camera is not moving. However if R, T are changing H will change too.

It seems like I'm missing something very important about the way rvecs and tvecs are defined in OpenCV.

答案1

得分: 1

在校准中,没有世界坐标系。

对于每张图片,只有图案物体)的框架和相机的框架,它们之间由一个变换关系(每张图片一个)相关联。

您可以决定是否有一个共同的相机框架(图案移动)或一个共同的图案框架(相机移动)。这对于校准没有影响。

文档中说:

> 从物体坐标空间到相机坐标空间执行基底变换

(物体 = 图案)

相应的变换矩阵可以写成

rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

因为这就是矩阵和向量的组合方式。您可以像多米诺骨牌一样排列它们,其中框架匹配。如果您想要将一个点从物体局部坐标变换到相机局部坐标,这是计算方法:

rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

它可以通过应用 cv.Rodrigues() 来获得一个3x3旋转矩阵,然后将其与平移向量组合成一个4x4矩阵。

rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

2: https://latex.codecogs.com/png.image?%5Cdpi%7B150%7D%5Cbg%7Bwhite%7D%5E%5Ctext%7BC%7D%5Cboldsymbol%7BT%7D_%5Ctext%7B物体%7D=%5Cbegin%7Bpmatrix%7D R&t%5C%5C0&1%5Cend%7Bpmatrix%7D

该变换意味着,如果您围绕模型原点旋转图案,则 tvec 不应该改变,而 tvec 具有 +X 将对应于图案位于相机前面空间的右半部分(+Y 在底半部分)。

如果您想要从相机局部坐标变换到物体局部坐标,您需要反转变换。

英文:

In calibration, there is no world coordinate system.

For each picture, there is only the frame of the pattern (object) and the frame of the camera, related by one transformation (per picture).

You decide if you have a common camera frame (pattern moving) or a common pattern frame (camera moving). This does not matter for the calibration.

Docs say:

> performs a change of basis from object coordinate space to camera coordinate space

(object = pattern)

The corresponding transformation matrix would be written as

rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

because that is how matrices and vectors compose. You can line them up like dominos, where the frames match. If you wanted to transform a point from object-local to camera-local, this is the calculation:

rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

And it can be built from applying cv.Rodrigues() to obtain a 3x3 rotation matrix, then combining that with the translation vector, into a 4x4 matrix.

rvecs和tvecs在OpenCV的calibrateCamera中为什么在每个视图中都不同?

That transformation implies that if you rotate the pattern around its model origin, the tvec should not change, and that a tvec having +X would correspond to the pattern being in the right half of the space in front of the camera (and +Y in the bottom half).

If you want to transform from camera-local coordinates into object-local coordinates, you need to invert the transformation.

答案2

得分: 0

rvectvec允许将世界坐标系中的点映射到相机坐标系中。如果您更改您的世界坐标系的原点或方向(如果您的世界坐标系与棋盘对齐,并且棋盘在每个帧中改变方向/位置,这可能是情况),那么rvectvec也会改变,即使相机没有实际改变位置。

英文:

rvec and tvec allows to map points in WORLD coordinate system to CAMERA coordinate system. If you change your world coordinate system origin or orientation (which is probably the case if your world coordinate system is aligned with a chessboard and the chessboard is changing orientation/position in each frame), then it will change rvec and tvec too even if the camera did not physically change position.

huangapple
  • 本文由 发表于 2023年6月29日 15:21:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578852.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定