码迷,mamicode.com
首页 > 其他好文 > 详细

Halcon相机标定

时间:2015-06-10 01:06:59      阅读:756      评论:0      收藏:0      [点我收藏+]

标签:

Halcon程序


 

*相机的内参数:
*f:相机的主矩,即焦距
*k:径向扭曲的大小,即径向畸变,一般不考虑切向畸变
*sx,sy:图像传感器在水平和垂直方向上相邻像素之间的距离
*cx,cy: 投影中心在成像平面的垂直投影

*相机外参数
*平移向量X,Y,Z
*旋转向量X,Y,Z

*透视矫正

dev_close_window()
dev_update_off()
dev_set_draw(‘margin‘)
read_image(Image, ‘scratch/scratch_perspective‘)
get_image_size(Image, Width, Height)
dev_open_window(0, 0, Width, Height, ‘black‘, WindowHandle)
set_display_font(WindowHandle, 16, ‘mono‘, ‘true‘, ‘false‘)
dev_display(Image)
disp_continue_message(WindowHandle, ‘black‘, ‘true‘)

*标定相机

*标定板描述文件
CaltabName := ‘caltab_30mm.descr‘

*初始内参数
*参数:焦距,厚度,单个像元的宽,单个像元的高,图形中心x,图像中心y,图形宽,图像高
StartCamPar := [0.012,0,0.0000055,0.0000055, Width/2, Height/2, Width, Height]

*创建标定数据模型
create_calib_data(‘calibration_object‘, 1, 1, CalibDataID)

*设置标定相机参数模型
set_calib_data_cam_param(CalibDataID, 0, ‘area_scan_division‘, StartCamPar)

*在标定模型中制定标定板描述文件
set_calib_data_calib_object(CalibDataID, 0, CaltabName)

***********************************
*获得标定板描述文件中标志点中心坐标
* caltab_points(CaltabName,X, Y, Z)
* NStartPose := []
* NRow := []
* NCol := []
***********************************

NumImages := 12
for i :=1 to NumImages by 1
read_image(Image, ‘scratch/scratch_calib_‘+i$‘02d‘)
dev_display(Image)
*寻找标定板区域
find_caltab(Image, Caltab, CaltabName, 3, 112, 5)
dev_set_color(‘green‘)
dev_display(Caltab)

*寻找标定板标志点坐标和预估外参
find_marks_and_pose(Image, Caltab, CaltabName, StartCamPar,128, 10, 18, 0.9, 15, 100, RCoord, CCoord, StartPose)
dev_set_color(‘red‘)
disp_circle(WindowHandle, RCoord, CCoord, gen_tuple_const(|RCoord|,2.5))
dev_set_part(0, 0, Height-1, Width-1)

*储存标定信息到标定板模型
set_calib_data_observ_points(CalibDataID, 0, 0, i, RCoord, CCoord,‘all‘, StartPose)

******************************
*组合所有标定外参数和中心坐标
* NStartPose := [NStartPose, StartPose]
* NRow := [NRow, RCoord]
* NCol := [NCol, CCoord]
******************************
endfor

******************************
*标定相机所有参数(可以不使用算子set_calib_data_observ_points)
* camera_calibration(X, Y, Z, NRow, NCol, StartCamPar, NStartPose, ‘all‘, CameraParam, NFinalPose, Errors)
******************************

*标定相机参数
calibrate_cameras(CalibDataID, Error)

*获取相机内参数
get_calib_data(CalibDataID,‘camera‘,0, ‘params‘, CamParam)

*获取相机外参数
get_calib_data(CalibDataID, ‘calib_obj_pose‘,[0,1],‘pose‘,PoseCalib)


*转换原点坐标
set_origin_pose(StartPose, -0.04, -0.03, 0.00075, Pose)

*设置标定后的图像一个像素代表的实际距离
PixelDist := 0.00013

*生成映像图像
gen_image_to_world_plane_map(Map, CamParam, Pose, Width, Height, Width, Height, PixelDist, ‘bilinear‘)

Imagefiles := [‘scratch/scratch_calib_01‘,‘scratch/scratch_perspective‘]
for i:= 1 to 2 by 1
read_image(Image, Imagefiles[i-1])
dev_set_window(WindowHandle)
dev_display(Image)


*应用映像转换图像
map_image(Image, Map,ImageMapped)

endfor


 

camera_parameters.dat文件内容

#
# INTERNAL CAMERA PARAMETERS
#

# ===== generic parameter syntax ==========================================
#
# Syntax: ParGroup: <pargroupname>;
# <pargroup_description>;
#
# <name> : <shortname> : <default_value>;
# <type> : <lower_bound> : <upper_bound>;
# <description>;
#
# [ <type> ::= BOOL|XBOOL|INT|FLOAT|DOUBLE|STRING ]
#
# =========================================================================

 

##############################################################################
#
# Camera : Parameter
# > Focus
# > Kappa
# > Sx
# > Sy
# > Cx
# > Cy
# > ImageWidth
# > ImageHeight
#
##############################################################################

ParGroup: Camera: Parameter;
"Internal camera parameters";

Focus:foc: 0.0161703501831527;
DOUBLE:0.0:;
"Focal length of the lens";

Kappa:kappa: -639.990421851654;
DOUBLE::;
"Radial distortion coefficient";

Sx:sx: 7.40108791846177e-006;
DOUBLE:0.0:;
"Width of a cell on the sensor";

Sy:sy: 7.4e-006;
DOUBLE:0.0:;
"Height of a cell on the sensor";

Cx:cx: 333.895895987285;
DOUBLE::;
"X-coordinate of the image center";

Cy:cy: 244.935973115852;
DOUBLE::;
"Y-coordinate of the image center";

ImageWidth:imgw: 652;
INT:1:32768;
"Width of the images";

ImageHeight:imgh: 494;
INT:1:32768;
"Height of the images";


#
# HALCON Version 12.0 -- Tue Apr 14 22:41:15 2015
#


 

camera_pose.dat文件内容

#
# 3D POSE PARAMETERS: rotation and translation
#

# Used representation type:
f 0

# Rotation angles [deg] or Rodriguez vector:
r 3.11886998639614 358.984666972156 30.2659614074603

# Translation vector (x y z [m]):
t 0.0248668618545196 0.0133955230862179 0.401474091384729

#
# HALCON Version 12.0 -- Tue Apr 14 22:41:15 2015

#


 

Halcon相机标定

标签:

原文地址:http://www.cnblogs.com/iluzhiyong/p/Halcon.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!