Halcon四 双目视觉的标定

本文分享了学习Halcon的博客链接,并给出一系列Halcon函数示例,包括获取图像指针、显示图像、储存标定观测值等。还展示了相机标定和图像校正的完整代码流程,如创建标定数据模型、读取图像、搜索标定板、提取标记和位姿、进行标定、获取参数、生成校正图等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文作者写的一系列博客,挺不错的学习halcon:http://blog.sina.com.cn/s/blog_442bfe0e0100yjtn.html

1.get_image_pointer1(Image : : : PointerTypeWidthHeight)

返回第一通道的点,图像数据类型,图像尺寸。

2.disp_image(Image : : WindowHandle : )

在输出窗口显示灰度图像

3.visualize_results_of_find_marks_and_pose (ImageL, WindowHandle1, RCoordL, CCoordL, StartPoseL, StartCamParL)

内部函数,显示初步标定的坐标系和MARKS中心,MARKS中线用十字线标出。

4.set_calib_data_observ_points( : : CalibDataIDCameraIdxCalibObjIdx,CalibObjPoseIdxRowColumnIndexPose : )

储存以点为基础的标定观测值,将观测值储存与标定数据句柄中。

5.calibrate_cameras( : : CalibDataID : Error)

根据标定数据模型中的值标定摄像机。

6.get_calib_data( : : CalibDataIDItemTypeItemIdxDataName : DataValue)

查询储存或计算得到的标定模型中的数据。

7.write_cam_par( : : CameraParamCamParFile : )

把相机内参数写入TXT文件

8.write_pose( : : PosePoseFile : )

把相机的位姿写入TXT文件

9.gen_binocular_rectification_map( : Map1Map2 : CamParam1CamParam2RelPose,SubSamplingMethodMapType : CamParamRect1CamParamRect2CamPoseRect1,CamPoseRect2RelPoseRect)

把相机参数和姿态作为输入,输出为校正图像和矫正后的参数和姿态。

10.map_image(ImageMap : ImageMapped : : )

dev_update_window ('off')
* Set the image path
ImgPath := '3d_machine_vision/stereo/'
* Read the first images to get their size
i := 0
read_image (ImageL, ImgPath+'calib_distorted_l_'+i$'03d')
read_image (ImageR, ImgPath+'calib_distorted_r_'+i$'03d') //分别读取左右目图像,编号长3位//
* Reopen the windows with an appropriate size
dev_close_window ()
dev_close_window ()
get_image_pointer1 (ImageL, PointerL, TypeL, WidthL, HeightL)
get_image_pointer1 (ImageR, PointerR, TypeR, WidthR, HeightR)
dev_open_window (0, 0, WidthL, HeightL, 'black', WindowHandle1)
dev_open_window (0, WidthL+5, WidthL, HeightL, 'black', WindowHandle2)//为左右目各打开一

                                                                        个图形窗口//
* Set the calibration plate description file
CaltabName := 'caltab_30mm.descr'
* Set the initial values for the interior camera parameters
StartCamParL := [0.0125, 0, 7.4e-6, 7.4e-6,WidthL/2.0,HeightL/2.0,WidthL,HeightL]
StartCamParR := StartCamParL
* parameter settings for find_caltab and find_marks_and_pose
SizeGauss := 3
MarkThresh := 120
MinDiamMarks := 5
StartThresh := 128
DeltaThresh := 10
MinThresh := 18
Alpha := 0.9
MinContLength := 15
MaxDiamMarks := 100
* Create a calibration data model in which all calibration data
* including the image coordinates of the calibration marks and
* the observation poses of the calibration plate will be
* accumulated
create_calib_data ('calibration_object', 2, 1, CalibDataID)      //创建标定数据模型句柄//
set_calib_data_cam_param (CalibDataID, 0, 'area_scan_division', StartCamParL)//在标定模型中

                                                                     设置相机的类型和原始参数//
set_calib_data_cam_param (CalibDataID, 1, 'area_scan_division', StartCamParR)
set_calib_data_calib_object (CalibDataID, 0, CaltabName)        //定义一个标定对象//

* Start the loop over the calibration images
for i := 0 to 10 by 1
    * Read and display the calibration images
    read_image (ImageL, ImgPath+'calib_distorted_l_'+i$'03d')
    read_image (ImageR, ImgPath+'calib_distorted_r_'+i$'03d')
    disp_image (ImageL, WindowHandle1)
    disp_image (ImageR, WindowHandle2)                         //读取并显示图像//
    * Search for the calibration plate
  find_caltab (ImageL, CaltabL, CaltabName, SizeGauss, MarkThresh, MinDiamMarks)
  find_caltab (ImageR, CaltabR, CaltabName, SizeGauss, MarkThresh, MinDiamMarks)//输出标定板区域//
    disp_region (CaltabL, WindowHandle1)
    disp_region (CaltabR, WindowHandle2)                     //显示标定区域//          
    * Extract the calibration marks and estimate an initial pose
    find_marks_and_pose (ImageL, CaltabL, CaltabName, StartCamParL, StartThresh, DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoordL, CCoordL, StartPoseL)
    * Visualize the extracted calibration marks and the
    * coordinate system defined by the estimated pose.
    visualize_results_of_find_marks_and_pose (ImageL, WindowHandle1, RCoordL, CCoordL, StartPoseL, StartCamParL)                      //显示初步标定的坐标系和MARKS中心//
    * Extraction of marks and pose as well as visualization of the
    * results for the second image.
    find_marks_and_pose (ImageR, CaltabR, CaltabName, StartCamParR, StartThresh, DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoordR, CCoordR, StartPoseR)
    visualize_results_of_find_marks_and_pose (ImageR, WindowHandle2, RCoordR, CCoordR, StartPoseR, StartCamParR)
    * Store the image coordinates of the calibration marks as well
    * as the estimated initial poses for all stereo pairs in the
    * calibration data model
    *  - Camera 0 is the (L)eft camera
    *  - Camera 1 is the (R)ight camera
    set_calib_data_observ_points (CalibDataID, 0, 0, i, RCoordL, CCoordL, 'all', StartPoseL)
    set_calib_data_observ_points (CalibDataID, 1, 0, i, RCoordR, CCoordR, 'all', StartPoseR)
                                                        //在标定数据模型句柄中储存标定结果//

endfor
* Perform the actual calibration
calibrate_cameras (CalibDataID, Errors)         //根据标定数据模型中的值标定摄像机//
* Get the calibrated camera parameters
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParamL)
get_calib_data (CalibDataID, 'camera', 1, 'params', CamParamR)      //获取摄像机参数//
* Since the left camera is the reference camera for the
* calib data model, the pose of the right camera is its
* pose relative to the left camera
get_calib_data (CalibDataID, 'camera', 1, 'pose', cLPcR)    //获取右目相对于左目的位姿//
* Store the results into files
write_cam_par (CamParamL, 'cam_left-125.dat')
write_cam_par (CamParamR, 'cam_right-125.dat')
write_pose (cLPcR, 'pos_right2left.dat')                    //将相机参数写入文件//
* Generate the rectification maps
gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, cLPcR, 1, 'geometric', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
 //把相机参数和姿态作为输入,输出为校正图像和矫正后的参数和姿态。//
* Read in a stereo image pair, aquired with the stereo camera system,
* which has been calibrated, just now.
read_image (ImageL, ImgPath+'caliper_distorted_l')
read_image (ImageR, ImgPath+'caliper_distorted_r')
* Rectify the stereo images and display them
map_image (ImageL, MapL, ImageRectifiedL)
map_image (ImageR, MapR, ImageRectifiedR)
dev_set_window (WindowHandle1)
dev_clear_window ()
dev_display (ImageRectifiedL)
dev_set_window (WindowHandle2)
dev_clear_window ()
dev_display (ImageRectifiedR)
disp_continue_message (WindowHandle1, 'black', 'true')
stop ()
dev_set_window (WindowHandle2)
dev_close_window ()
dev_update_window ('on')
dev_set_window (WindowHandle1)
dev_clear_window ()
dev_display (ImageRectifiedL)
clear_calib_data (CalibDataID)

转载于:https://www.cnblogs.com/6-6-8-8/p/9549622.html

Halcon相机标定代码.hdev 1.初始化 for example: Full image (640*480) Subsampling (320*240) ImageWidth 640 320 ImageHeight 480 240 2.标定板初始化 CaltabName := 'caltab_30mm.descr'//标定板描述文件 set_calib_data_calib_object (CalibDataID, 0, CaltabName) 3.创建数据模型 create_calib_data ('calibration_object', 1, 1, CalibDataID) 4.获取标定图片 相机拍摄不同位姿下图片8-15张,拍摄图片时标定板尽量覆盖整个视场(标定板要根据工作距离、视场大小定制);拍摄图片上的圆直径不得小于10个像素 5.加载所有图像,寻找标定板区域,确定圆心,将结果加载到组元中 for I := 1 to NumImages by 1 ... acquire image ... find_caltab (Image, Caltab, CaltabName, SizeGauss, MarkThresh, MinDiamMarks) find_marks_and_pose (Image, Caltab, CaltabName, StartCamPar, StartThresh, \ DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoord, CCoord, StartPose) set_calib_data_observ_points (CalibDataID, 0, 0, I, RCoord, CCoord, 'all', StartPose) endfor 下面将Halcon中提取目标点的大致原理说一下: 首先find_caltab 算子对图像高斯滤波(核大小为SizeGauss),接着阈值分割(与之大小为MarkThresh)将标定板的区域找出来, find_marks_and_pose 算子对区域中的圆进行分割,找到圆的个数,周长,坐标位置等应该和标定板描述文件中的一致,否则会自动调整StartThresh,使得StartThresh按照DeltaThresh步长减小到MinThresh,知道找到准确的圆心。 6.有了所有图像中的圆心就可以标定了 calibrate_cameras (CalibDataID, Errors) 返回平均投影误差Errors
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值