1、为什么要用手眼标定(在贴片机上定位已调通)
参考手眼标定特别是眼在手上在网上的文章很多,但很多在实际中调试不通。在定位时候,往往希望相机能返回的是机械的世界坐标,而不是相机的的图像坐标。从而间接计算出相机坐标系与机械坐标世界坐标转换矩阵,以镜头中心为参考点。
2、手眼标定的实现
stp1:移动模组3*3 ,3行3列,分别模组走一个点(Bx,By),相机拍照获取一张图片Mark的坐标(Ax,Ay)的坐标。
*已知模组的9个点
Ax:=[825.505,1116.06,1405.89,830.793,1121.89,1412.44,836.321,1127.35,1417.95]
Ay:=[1413.87,1419.22,1423.91,1122.52,1128.24,1133.46,830.913,836.734,842.063]
*相机Mark获取的坐标
Bx:=[-152.7289,-153.7289,-154.7289,-152.7289,-153.7289,-154.7289,-152.7289,-153.7289,-154.7289]
By:=[-92.8409,-92.8409,-92.8409,-93.8409,-93.8409,-93.8409,-94.8409,-94.8409,-94.8409]
stp2:仿射变换求出仿射矩阵HomMat2D
vector_to_hom_mat2d ( Ax, Ay, Bx, By,HomMat2D)
stp3:求世界坐标
手眼标定,以相机中心
1、求出base,以图像dqx1, dqy1(0,0)为参考点
affine_trans_point_2d (HomMat2D, 0, 0, dqx1, dqy1)
2、求出图像Mark坐标(pixx:=1417.95,pixy:=842.063)到图像中心点坐标的世界坐标(标定时候的)中心点(1024,1224)
dpix:=1024-pixx
dpiy:=1224-pixy
affine_trans_point_2d (HomMat2D, dpix, dpiy, dqx, dqy)
3、求出偏差Offset dqx2,dqy2
dqx2:=dqx-dqx1
dqy2:=dqy-dqy1
4、模组获取反馈的运动控制的坐标realx,raaly,求出镜头中心实际坐标realx3,realy3
realx3:=realx+dqx2
realy3:=raaly+dqy2
read_image(Image, 'printer_chip/printer_chip_01')
*已知A坐标系的9个点
Ax:=[825.505,1116.06,1405.89,830.793,1121.89,1412.44,836.321,1127.35,1417.95]
Ay:=[1413.87,1419.22,1423.91,1122.52,1128.24,1133.46,830.913,836.734,842.063]
*待识别的B坐标点,和上面的A坐标系点一一对应
Bx:=[-152.7289,-153.7289,-154.7289,-152.7289,-153.7289,-154.7289,-152.7289,-153.7289,-154.7289]
By:=[-92.8409,-92.8409,-92.8409,-93.8409,-93.8409,-93.8409,-94.8409,-94.8409,-94.8409]
* for Index := 1 to 9 by 1
* dev_display (Image)
* 以下过程为在B坐标系找A中的9个点
* draw_rectangle1 (200000, Row1, Column1, Row2, Column2)
* gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
* reduce_domain (Image, Rectangle, ImageReduced)
* binary_threshold (ImageReduced, Region, 'max_separability', 'light', UsedThreshold)
* connection (Region, ConnectedRegions)
* select_shape (ConnectedRegions, SelectedRegions, 'roundness', 'and', 0.7, 1)
* select_shape (SelectedRegions, SelectedRegion2, 'rb', 'and', 32, 100)
* fill_up (SelectedRegions, RegionFillUp)
*找到了B坐标系的点(Row,Column)
* area_center (RegionFillUp, Area, Row, Column)
* Bx:=[Bx,Column]
* By:=[By,Row]
* endfor
*得到目标变换矩阵HomMat2D
vector_to_hom_mat2d ( Ax, Ay, Bx, By,HomMat2D)
vector_to_hom_mat2d ( Bx, By, Ax, Ay,HomMat2DINV)
********new realx raaly机械反馈的坐标
realx:=-154.7289
raaly:=-94.8409
pixx:=1417.95
pixy:=842.063
dpix:=1024-pixx
dpiy:=1224-pixy
affine_trans_point_2d (HomMat2D, dpix, dpiy, dqx, dqy)
affine_trans_point_2d (HomMat2D, 0, 0, dqx1, dqy1)
dqx2:=dqx-dqx1
dqy2:=dqy-dqy1
realx3:=realx+dqx2
realy3:=raaly+dqy2