1

I am planning on making a robotic arm. I have a camera mounted on the arm. I am using Opencv with python3 to do IP.

I want the arm to detect the point on the ground and the servos to move accordingly. I have completed the part of detection and calculating the world coordinates. Also, the inverse kinematics that is required.

The problem here is that I have calibrated the camera for a certain height (20 cm). So, the correct world coordinates are received at the height of 20 cm only. I want the camera to keep correcting the reading at every 2s that it moves towards the ground (downward).

Is there a way that I can do the calibration dynamically, and give dynamic coordinates to my arm? I don't know if this is the right approach. If there is another method to do this, please help.

4

1 回答 1

1

我假设您正在使用该undistort函数首先使图像不失真,然后使用旋转矢量(rcvt)和平移矢量(tvctdistortCoeffs来获取世界坐标。正确的坐标只能在该特定高度获得,因为rvcttvct将根据用于校准的(棋盘的)正方形大小而变化。

克服这个问题的一个聪明方法是轻松消除旋转矢量和平移矢量。

由于相机校准常数在任何高度/旋转都保持不变,因此可以使用它。另外,不要每2秒校准一次(这会消耗太多CPU),直接使用下面的方法来获取值!

假设(img_x, img_y)是您需要转换为世界坐标的图像坐标,(world_x, world_y)并且cameraMatrix是您的相机矩阵。对于这种方法,您需要知道distance_cam,即您的对象与相机的垂直距离。

使用 python 和 opencv,使用以下代码:

import numpy as np
from numpy.linalg import inv

img_x, img_y = 20, 30 # your image coordinates go here
world_coord = np.array([[img_x], [img_y], [1]]) # create a 3x1 matrix
world_coord = inv(cameraMatrix) * world_coord # use formula cameraMatrix^(-1)*coordinates
world_coord = world_coord * distance_cam 
world_x = world_coord[0][0]
world_y = world_coord[1][1]
print(world_x, world_y)

起初,我们可能没有意识到世界坐标中的单位并不重要。乘以相机矩阵的倒数后,您定义了 x/z 比率,它是无单位的。因此,您可以distance_cam在任何单位中选择 ,最终结果将以 为单位distance_cam,也就是说,如果distance_cam在 中mm,那么world_x, world_y也将在 中mm

于 2018-07-29T15:45:33.027 回答