Halcon标定步骤

1.设置相机内部参数的初始值

StartCamPar := [0.016,0,0.0000074,0.0000074,326,247,652,494]
set_calib_data_cam_param (CalibDataID, 0, 'area_scan_division', StartCamPar)

  1.1 相机型号

      (1)面阵

      (2)线阵

  1.2 参数设置(这里只讲面阵相机)

      (1)Division畸变模型

          CameraParam:[Focus, Kappa, Sx, Sy, Cx, Cy, ImageWidth, ImageHeight]

      (2)Polynomial 畸变模型

          CameraParam:[Focus, K1, K2, K3, P1, P2, Sx, Sy, Cx, Cy, ImageWidth, ImageHeight]

          注:当镜头为远心镜头时,Focus=0;

  1.3 畸变类型的选择

      Division畸变模型只适用于进度要求不是很高,标定图片数量较少的情况;Polynomial 畸变模型对镜像

      畸变和切向畸变都校正,精度较高,花费时间长。

  1.4 标定时个参数值的确定技巧

      Focus f:镜头的标称焦距, e.g., 0.016 m.; 对于远心镜头为0.
      κ: 一般去0.0
      Or:
      K1, K2, K3,P1, P2:可全部初始化为0
      Sx: 由CCD\CMOS确定建议取值如下:
           Full image (640*480) Subsampling (320*240)
           1/3"-Chip 0.0000055 m 0.0000110 m
           1/2"-Chip 0.0000086 m 0.0000172 m
           2/3"-Chip 0.0000110 m 0.0000220 m
      Sy: 由CCD\CMOS确定建议取值如下:

          for example:
           Full image (640*480) Subsampling (320*240)
           1/3"-Chip 0.0000055 m 0.0000110 m
           1/2"-Chip 0.0000086 m 0.0000172 m
           2/3"-Chip 0.0000110 m 0.0000220 m

      Cx and Cy: 光心坐标初始值,建议取值如下:
         for example:
          Full image (640*480) Subsampling (320*240)
          Cx 320.0 160.0
          Cy 240.0 120.0
      ImageWidth,ImageHeight:有实际图片大小来初始化该值
       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

以下是一个伪代码段.......(明天再续)
* Calibration parameters
CaltabDescr := 'caltab_100mm.descr'
CaltabThickness := 0.0064
NumCameras := 4
NumCalibObjects := 1
NumPoses := 20
CameraType := 'area_scan_polynomial'
StartCamPar := [0.0085, 0.0, 0.0, 0.0, 0.0, 0.0, 6e-6, 6e-6, Width*.5, Height*.5, Width, Height]
*
* Create camera calibration model and set parameters
create_calib_data ('calibration_object', NumCameras, NumCalibObjects, CalibDataID)
* Set used camara type
set_calib_data_cam_param (CalibDataID, 'all', CameraType, StartCamPar)
* Set used calibration object
set_calib_data_calib_object (CalibDataID, 0, CaltabDescr)

你可能感兴趣的:(HALCON)