【Halcon】Halcon双目标定

Halcon双目标定


* 设置图片路径
ImgPath := 'E:/2222/'
* 读取第一幅图像,并获取图像尺寸
Index := 1
read_image (ImageL, ImgPath + 'L' + Index$'02d')
read_image (ImageR, ImgPath + 'R' + Index$'02d')
* 打开合适尺寸大小的窗口
dev_close_window ()
dev_update_off ()
get_image_size (ImageL, WidthL, HeightL)
dev_open_window (0, 0, 0.4*WidthL,0.4* HeightL, 'black', WindowHandle1)
dev_set_draw ('margin')
dev_set_color ('green')
set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')
get_image_size (ImageR, WidthR, HeightR)
dev_open_window (0, 0.4*WidthL + 12, 0.4*WidthL, 0.4*HeightL, 'black', WindowHandle2)
dev_set_draw ('margin')
dev_set_color ('green')
* 读取标定板模型.
CaltabFile := 'caltab_100mm.descr'
caltab_points (CaltabFile, X, Y, Z)
* 为相机内参设置初始值
StartCamParL := [0.016,0,3.75e-6,3.75e-6,WidthL / 2.0,HeightL / 2.0,WidthL,HeightL]
StartCamParR := StartCamParL
* find_caltab 和 find_marks_and_pose参数设置
SizeGauss := 3
MarkThresh := 120
MinDiamMarks := 5
StartThresh := 128
DeltaThresh := 10
MinThresh := 18
Alpha := 0.9
MinContLength := 15
MaxDiamMarks := 100
* 创建数组,用于存放图像坐标系下的标定点坐标和标定板的初始位姿
RowsL := []
ColsL := []
StartPosesL := []
RowsR := []
ColsR := []
StartPosesR := []
*循环读取标定图像
for Index := 1 to 8 by 1
    * 读取标定图像
    read_image (ImageL, ImgPath + 'L' + Index$'02d')
    read_image (ImageR, ImgPath + R' + Index$'02d')
    * 寻找标定板
    find_caltab (ImageL, CaltabL, CaltabFile, SizeGauss, MarkThresh, MinDiamMarks)
    find_caltab (ImageR, CaltabR, CaltabFile, SizeGauss, MarkThresh, MinDiamMarks)
    * 显示标定板区域
    dev_set_window (WindowHandle1)
    dev_display (ImageL)
    dev_display (CaltabL)
    dev_set_window (WindowHandle2)
    dev_display (ImageR)
    dev_display (CaltabR)
    * (左相机)提取标记点和标定板位姿,并显示位姿坐标
    find_marks_and_pose (ImageL, CaltabL, CaltabFile, StartCamParL, StartThresh, DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoordL, CCoordL, StartPoseL)
    disp_caltab (WindowHandle1, CaltabFile, StartCamParL, StartPoseL, 1)
    *(右相机)提取标记点和标定板位姿,并显示位姿坐标
    find_marks_and_pose (ImageR, CaltabR, CaltabFile, StartCamParR, StartThresh, DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoordR, CCoordR, StartPoseR)
    disp_caltab (WindowHandle2, CaltabFile, StartCamParR, StartPoseR, 1)
    * 计算标记点在图像坐标系下的位姿,并估算所有图像对间的相对位姿
    RowsL := [RowsL,RCoordL]
    ColsL := [ColsL,CCoordL]
    StartPosesL := [StartPosesL,StartPoseL]
    RowsR := [RowsR,RCoordR]
    ColsR := [ColsR,CCoordR]
    StartPosesR := [StartPosesR,StartPoseR]
endfor
*
* 执行标定
* 
binocular_calibration (X, Y, Z, RowsL, ColsL, RowsR, ColsR, StartCamParL, StartCamParR, StartPosesL, StartPosesR, 'all', CamParamL, CamParamR, NFinalPoseL, NFinalPoseR, cLPcR, Errors)
* 可以将标定结果存入文件中:
* write_cam_par (CamParamL, 'cam_left-125.dat')
* write_cam_par (CamParamR, 'cam_right-125.dat')
* write_pose (cLPcR, 'pos_right2left.dat')
* 生成校正的映射图
gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, cLPcR, 1, 'geometric', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
* 读取已标定系统的一个图像对
read_image (ImageL, ImgPath + 'L1')
read_image (ImageR, ImgPath + 'R1')
* 校正图像对并显示
map_image (ImageL, MapL, ImageRectifiedL)
map_image (ImageR, MapR, ImageRectifiedR)
* 检查校正图像的对极约束并显示结果(包含一些对应的极线)
*check_epipolar_constraint (ImageRectifiedL, ImageRectifiedR, RectCamParL, RectCamParR, WindowHandle1, WindowHandle2, CaltabFile, EpipolarError)

获取的标定结果如下
标定结果

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值