小言_互联网的博客

重码网halcon编程5——双目立体视觉原理、双目标定、测量高度

299人阅读  评论(0)

双目立体视觉原理

双目标定








代码







测量高度




*关闭图像窗口更新
dev_update_window ('off')

*关闭变量更新
dev_update_var ('off')

*关闭程序计数器更新
dev_update_pc ('off')

*关闭窗口
dev_close_window ()

*打开新窗口
dev_open_window (0, 0, 672, 484, 'black', WindowHandle)

*设置字体显示信息
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')

*读取左面相机采集的图像
read_image (ImageL, 'stereo/board/board_l_01')

*读取右面相机采集的图像
read_image (ImageR, 'stereo/board/board_r_01')

*获取图像的大小
get_image_size (ImageR, Width, Height)

*根据双目立体视觉标定获取到左右相机的摄像机内部参数和右相机相对左相机的位姿
*左相机的摄像机内部参数
CamParamL := [0.0130507774353,-665.817817207,1.4803417027e-5,1.48e-5,155.89225769,126.70664978,320,240]
*右相机的摄像机内部参数
CamParamR := [0.0131776504517,-731.860636733,1.47997569293e-5,1.48e-5,162.98210144,119.301040649,320,240]
*右相机相对左相机的位姿
RelPose := [0.153573364258,-0.00373362231255,0.0447351264954,0.174289124775,319.843388114,359.894955219,0]

*获取非标准外极限图像和标准外极限图像之间的变换矩阵(映射图像)
gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, RelPose, 1, 'geometric', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)

*根据变换矩阵对左边相机进行图像校正
map_image (ImageL, MapL, ImageRectifiedL)

*根据变换矩阵对右边相机进行图像校正
map_image (ImageR, MapR, ImageRectifiedR)

binocular_disparity (ImageRectifiedL, ImageRectifiedR, Disparity, Score1, 'ncc', 17, 17, 5, 0, 60, 1, 0.1, 'none', 'none')
*根据左右相机的校正图像计算深度信息
binocular_distance_mg (ImageRectifiedL, ImageRectifiedR, Distance, Score, RectCamParL, RectCamParR, RectLPosRectR, 1, 10, 5, 0, 'false', 'default_parameters', 'accurate')

*清除窗口内容
dev_clear_window ()

*显示距离图像
dev_display (Distance)

*计算IC的高度
gen_rectangle2 (IC, 107.276, 62.0363, rad(-25.6343), 7.64174, 6.41978)
gen_rectangle2 (PCB, 101.986, 145.771, rad(4.75463), 7.97698, 6.76498)
get_grayval (Distance, 107.276, 62.0363, IC_Grayval)
get_grayval (Distance, 101.986, 145.771, PCB_Grayval)
IC_Height:=(PCB_Grayval-IC_Grayval)*100

*显示结果
dev_display (ImageRectifiedL)
set_tposition (WindowHandle, 103, 54)
write_string (WindowHandle, 'IC零件的高度是:'+IC_Height+'cm')

转载:https://blog.csdn.net/qq_42832272/article/details/101287531
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场