原文做者寫的一系列博客,挺不錯的學習halcon:http://blog.sina.com.cn/s/blog_442bfe0e0100yjtn.htmlphp
1.get_image_pointer1(Image : : : Pointer, Type, Width, Height)html
返回第一通道的點,圖像數據類型,圖像尺寸。windows
2.disp_image(Image : : WindowHandle : )app
在輸出窗口顯示灰度圖像函數
3.visualize_results_of_find_marks_and_pose (ImageL, WindowHandle1, RCoordL, CCoordL, StartPoseL, StartCamParL)oop
內部函數,顯示初步標定的座標系和MARKS中心,MARKS中線用十字線標出。學習
4.set_calib_data_observ_points( : : CalibDataID, CameraIdx, CalibObjIdx,CalibObjPoseIdx, Row, Column, Index, Pose : )ui
儲存以點爲基礎的標定觀測值,將觀測值儲存與標定數據句柄中。spa
5.calibrate_cameras( : : CalibDataID : Error)3d
根據標定數據模型中的值標定攝像機。
6.get_calib_data( : : CalibDataID, ItemType, ItemIdx, DataName : DataValue)
查詢儲存或計算獲得的標定模型中的數據。
7.write_cam_par( : : CameraParam, CamParFile : )
把相機內參數寫入TXT文件
8.write_pose( : : Pose, PoseFile : )
把相機的位姿寫入TXT文件
9.gen_binocular_rectification_map( : Map1, Map2 : CamParam1, CamParam2, RelPose,SubSampling, Method, MapType : CamParamRect1, CamParamRect2, CamPoseRect1,CamPoseRect2, RelPoseRect)
把相機參數和姿態做爲輸入,輸出爲校訂圖像和矯正後的參數和姿態。
10.map_image(Image, Map : 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 themmap_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)