首页 > 其他分享 >halcon 双目相机标定

halcon 双目相机标定

时间:2024-01-19 10:56:00浏览次数:24  
标签:CaltabFile calibration image 标定 dev halcon 相机 marks find

* Application program to demonstrate the calibration of
* a binocular stereo system using the operators
* find_caltab, find_marks_and_pose, and binocular_calibration.
* 
* As an alternative, a calibration data model could be used.
* Please refer to the example program
* examples/solution_guide/3d_vision/stereo_calibration.hdev.
* 
* We have a stereo setup of two cameras ('camera1 is left of camera2').
* Both cameras will be calibrated by a couple of images of
* a 30mm calibration plate. An image pair will be rectified
* to epipolar images and the epipolar constraint will be checked.
* ---------------------------------------------------------
* Set the image path
ImgPath := 'stereo/board/'
* Read the first images to get their size
Index := 1
read_image (ImageL, ImgPath + 'calib_l_' + Index$'02d')
read_image (ImageR, ImgPath + 'calib_r_' + Index$'02d')
* Reopen the windows with an appropriate size
dev_close_window ()
dev_update_off ()
get_image_size (ImageL, WidthL, HeightL)
dev_open_window (0, 0, WidthL, 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, WidthL + 12, WidthL, HeightL, 'black', WindowHandle2)
dev_set_draw ('margin')
dev_set_color ('green')
* Read the model calibration points.
CaltabFile := 'caltab_30mm.descr'
caltab_points (CaltabFile, X, Y, Z)
* Set the initial values for the internal camera parameters
gen_cam_par_area_scan_division (0.0125, 0, 1.48e-5, 1.48e-5, WidthL / 2.0, HeightL / 2.0, WidthL, HeightL, StartCamParL)
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 the tuples in which the image coordinates of the
* calibration marks and the initial poses will be accumulated
RowsL := []
ColsL := []
StartPosesL := []
RowsR := []
ColsR := []
StartPosesR := []
* Start the loop over the calibration images
for Index := 1 to 15 by 1
    * Read the calibration images
    read_image (ImageL, ImgPath + 'calib_l_' + Index$'02d')
    read_image (ImageR, ImgPath + 'calib_r_' + Index$'02d')
    * Search for the calibration plate
    find_caltab (ImageL, CaltabL, CaltabFile, SizeGauss, MarkThresh, MinDiamMarks)
    find_caltab (ImageR, CaltabR, CaltabFile, SizeGauss, MarkThresh, MinDiamMarks)
    * Display calibration plate regions
    dev_set_window (WindowHandle1)
    dev_display (ImageL)
    dev_display (CaltabL)
    dev_set_window (WindowHandle2)
    dev_display (ImageR)
    dev_display (CaltabR)
    * Extraction of marks and pose as well as visualization of the
    * results for the second image.
    find_marks_and_pose (ImageL, CaltabL, CaltabFile, StartCamParL, StartThresh, DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoordL, CCoordL, StartPoseL)
    disp_caltab (WindowHandle1, CaltabFile, StartCamParL, StartPoseL, 1)
    * Extraction of marks and pose as well as visualization of the
    * results for the second image.
    find_marks_and_pose (ImageR, CaltabR, CaltabFile, StartCamParR, StartThresh, DeltaThresh, MinThresh, Alpha, MinContLength, MaxDiamMarks, RCoordR, CCoordR, StartPoseR)
    disp_caltab (WindowHandle2, CaltabFile, StartCamParR, StartPoseR, 1)
    * Accumulate the image coordinates of the calibration marks
    * as well as the estimated initial poses for all stereo pairs,
    * where the poses has been estimated consistently.
    RowsL := [RowsL,RCoordL]
    ColsL := [ColsL,CCoordL]
    StartPosesL := [StartPosesL,StartPoseL]
    RowsR := [RowsR,RCoordR]
    ColsR := [ColsR,CCoordR]
    StartPosesR := [StartPosesR,StartPoseR]
endfor
* Perform the actual calibration
binocular_calibration (X, Y, Z, RowsL, ColsL, RowsR, ColsR, StartCamParL, StartCamParR, StartPosesL, StartPosesR, 'all', CamParamL, CamParamR, NFinalPoseL, NFinalPoseR, cLPcR, Errors)
* If required, save the results to disk:
* 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, 'viewing_direction', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
* Read in a stereo image pair, acquired with the stereo camera system,
* which has been calibrated, just now.
read_image (ImageL, ImgPath + 'calib_l_01')
read_image (ImageR, ImgPath + 'calib_r_01')
* Rectify the stereo images and display them
map_image (ImageL, MapL, ImageRectifiedL)
map_image (ImageR, MapR, ImageRectifiedR)
* Check the epipolar constraint on the rectified images,
* (the differences of the features' row coordinates should be small)
* and visualize the result (including some corresponding epipolar lines)
check_epipolar_constraint (ImageRectifiedL, ImageRectifiedR, RectCamParL, RectCamParR, WindowHandle1, WindowHandle2, CaltabFile, EpipolarError)

 

标签:CaltabFile,calibration,image,标定,dev,halcon,相机,marks,find
From: https://www.cnblogs.com/echo-efun/p/17974159

相关文章

  • halcon #正则表达式
    此处提供了正则表达式语法的摘要。基本上正则表达式中的每个字符都表示要匹配的文本,除了以下具有特殊含义的符号(所描述的语法与Perl兼容):^匹配字符串的开头$匹配字符串末尾(允许使用尾随换行符).匹配除换行符以外的任何字符[...]匹配括号中列出的任何字符文本......
  • halcon中的tuple用法
    a:=[-10,100,130]t:=[-0.5,0.5,1]tuple_abs(a,Abs)*计算一个元组的绝对值*[10,100,130]tuple_acos(t,ACos)*计算一个元组的反余弦*参数1:输入元组。限制:-1<=t<=1*[2.0944,1.0472,0.0]tuple_add(a,t,Sum)*两个元组相加*[-10.5,100.5,131]tuple_asin......
  • 相机标定原理
    相机标定后可以得到什么?相机的内参矩阵A(dx,dy,r,u,v,f),外参矩阵[R|T]、畸变系数[k1,k2,k3,~,p1,p2,~]。•内参矩阵各元素意义:一个像素的物理尺寸dx和dy,焦距f,图像物理坐标的扭曲因子r,图像原点相对于光心成像点的的纵横偏移量u和v(像素为单位)。•外参矩阵:世界坐标系转换到相机坐标系......
  • uniapp调用相机
    uni.chooseImage({count:1,//默认9sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有sourceType:['album','camera'],//album从相册选图,camera使用相机success:function(res){console.log(JSON.stringify(res.temp......
  • Three.js——十五、Box3、相机动画、lookAt()视线方向、管道漫游案例、OrbitControls
    正投影相机正投影相机和透视相机的区别如果都以高处俯视去看整个场景,正投影相机就类似于2d的可视化的效果,透视相机就类似于人眼观察效果调整left,right,top,bottom范围大小如果你想整体预览全部立方体,就需要调整相机的渲染范围,比如设置上下左右的范围。使用场景:正投影可以......
  • halcon 标定
    1.标定板类型  a.Calibrationplatewithhexagonallyarrangedmarks  带有六边形排列标记的校准板    b.Calibrationplatewithrectangularlyarrangedmarks  带有矩形排列标记的校准板 2.标定过程a.准备校准输入数据1.create_calib_data ......
  • Halcon 相机外部参数标定例程一(camera_calibration_external.hdev)
    1.create_calib_data—CreateaHALCONcalibrationdatamodel  创建一个HALCON校准数据模型2.read_cam_par—Readinternalcameraparametersfromafile  从文件中读取相机内部参数  3.set_calib_data_cam_param—Settypeandinitialparametersofa......
  • Unity知识总结系列(二):相机跟随人物的几种方式
    相机跟随人物的几种方式1、最简单,无代码,固定距离,固定视角2、代码控制,固定距离,固定视角,对1进行改进3、代码控制,固定距离,固定视角,直接移动,不会旋转4、代码控制,固定距离,固定视角,插值移动(因为Update和LateUpdate刷新率不同,会有抖动现象,不建议使用)5、代码控制,固定距离,固定视角,平滑......
  • Halcon threshold_sub_pix (Operator)
    read_image(Image,'fabrik')threshold_sub_pix(Image,Border,35)dev_display(Border)Image是输入的原始图像,Threshold是设定的阈值,Width和Height是像素值计算区域的大小,ThresholdedRegion是经过分割后得到的二值化结果。在对图像进行二值化处理时,threshold_sub_pix函数会对每个像......
  • WPF Halcon机器视觉和运动控制软件通用框架,插件式开发,开箱即用 仅供学习!
    点我下载,仅供个人学习使用参考easyvision开发,集成几十个软件算子此版本以添加ui设计器。具体功能如上所示,可以自定义变量,写c#脚本,自定义流程,包含了halcon脚本和封装的算子,可自定义ui,通过插件形式开发很方便拓展自己的功能。......