其他分享
首页 > 其他分享> > halcon学习-相机标定与图像径向或透视畸变的校正

halcon学习-相机标定与图像径向或透视畸变的校正

作者:互联网

1.初始化相机并设置相机内部参数和相机类型,确定校准目标。
gen_cam_par_area_scan_division
create_calib_data
set_calib_data_cam_param
set_calib_data_calib_object
2.校正相机
find_calib_object
get_calib_data(CalibDataID, ‘camera’, 0, ‘init_params’, StartCamPar)
get_calib_data_observ_points
get_calib_data_observ_contours
gen_cross_contour_xld

calib_camera
calibrate_cameras
get_calib_data (CalibDataID, ‘camera’, 0, ‘params’, CamParam)

3.校正前的准备
get_calib_data (CalibDataID, ‘calib_obj_pose’, [0,I - 1], ‘pose’, Pose)
获取目标位姿
set_origin_pose (Pose, -1.125, -1.0, 0, PoseNewOrigin)
在给定DXDYDZ平面内平移原点位姿
gen_image_to_world_plane_map (MapSingle, CamParam, PoseNewOrigin, 768, 576, 900, 800, 0.0025, ‘bilinear’)
生成一个投影映射图,它描述了在一个世界坐标系中图像平面与z=0平面(测量平面)之间的映射。此映射可用于使用map_image操作符对图像进行校正。校正后的图像既无径向畸变,也无透视畸变;它对应于由垂直于测量平面的无畸变相机获取的图像

concat_obj(Maps, MapSingle, Maps)

4.校正
map_image(Image, MapSingle, ImageMapped)

学习的算子:
pose_to_hom_mat3d将三维位姿转换为齐次变换矩阵。

affine_trans_point_3d对点应用任意仿射三维变换。
将模型点转换为摄像机坐标系。

project_3d_point项目3D点进入(子)像素图像坐标。
将一个或多个3D点(坐标为X、Y和Z)投影到图像平面(以像素为单位),并以行和列返回结果。坐标X、Y、Z在摄像机坐标系中给定,即,它们描述点相对于摄像机的位置。
例程:

dev_close_window ()
dev_open_window (0, 0, 768 / 2, 576 / 2, 'black', WindowHandle1)
set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')
dev_update_off ()
dev_set_draw ('margin')
dev_set_line_width (2)
* 
* Calibrate the camera.
* 
CalTabDescrFile := 'caltab_big.descr'
* Make sure that the file 'CaltabName' is in the current directory,
* the HALCONROOT/calib directory, or use an absolute path
gen_cam_par_area_scan_division (0.008, 0, 0.0000086, 0.0000086, 384, 288, 768, 576, StartCamPar)
create_calib_data ('calibration_object', 1, 1, CalibDataID)
set_calib_data_cam_param (CalibDataID, 0, [], StartCamPar)
set_calib_data_calib_object (CalibDataID, 0, CalTabDescrFile)
NumImages := 10
read_image (Images, 'calib/calib-3d-coord-' + [1:NumImages]$'02d')
for I := 1 to NumImages by 1
    select_obj (Images, Image, I)
    dev_display (Image)
    Message := 'Find calibration plate in\nall calibration images (' + I + '/' + NumImages + ')'
    disp_message (WindowHandle1, Message, 'window', 12, 12, 'black', 'true')
    * Find the calibration plate
    find_calib_object (Image, CalibDataID, 0, 0, I - 1, [], [])
    get_calib_data (CalibDataID, 'camera', 0, 'init_params', StartCamPar)
    get_calib_data_observ_points (CalibDataID, 0, 0, I - 1, Row, Column, Index, Pose)
    get_calib_data_observ_contours (Contours, CalibDataID, 'caltab', 0, 0, I - 1)
    gen_cross_contour_xld (Cross, Row, Column, 6, 0.785398)
    dev_set_color ('green')
    dev_display (Contours)
    dev_set_color ('yellow')
    dev_display (Cross)
endfor
disp_continue_message (WindowHandle1, 'black', 'true')
stop ()
calibrate_cameras (CalibDataID, Error)
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParam)
gen_empty_obj (Maps)
for I := 1 to NumImages by 1
    * Obtain the pose of the calibration table
    get_calib_data (CalibDataID, 'calib_obj_pose', [0,I - 1], 'pose', Pose)
    set_origin_pose (Pose, -1.125, -1.0, 0, PoseNewOrigin)
    * Generate map
    gen_image_to_world_plane_map (MapSingle, CamParam, PoseNewOrigin, 768, 576, 900, 800, 0.0025, 'bilinear')
    concat_obj (Maps, MapSingle, Maps)
endfor
clear_calib_data (CalibDataID)
* 
* Map the images
* 
dev_open_window (0, 391, 900 / 2, 800 / 2, 'black', WindowHandle2)
set_display_font (WindowHandle2, 14, 'mono', 'true', 'false')
Button := 0
NumImage := 1
for I := 1 to NumImages by 1
    dev_set_window (WindowHandle1)
    dev_set_part (0, 0, 575, 767)
    dev_clear_window ()
    select_obj (Images, Image, I)
    dev_display (Image)
    select_obj (Maps, MapSingle, I)
    map_image (Image, MapSingle, ImageMapped)
    dev_set_window (WindowHandle2)
    dev_set_part (0, 0, 799, 899)
    dev_clear_window ()
    dev_display (ImageMapped)
    Message := 'Calibration image (' + I + '/' + NumImages + ')'
    disp_message (WindowHandle1, Message, 'window', 12, 12, 'black', 'true')
    Message := 'Mapped image'
    disp_message (WindowHandle2, Message, 'window', 12, 12, 'black', 'true')
    if (I < NumImages)
        disp_continue_message (WindowHandle1, 'black', 'true')
        stop ()
    endif
endfor

标签:set,get,标定,dev,halcon,畸变,calib,CalibDataID,data
来源: https://blog.csdn.net/weixin_41082581/article/details/97149482