手眼标定eye-to-hand 示例:handeye_stationarycam_calibration
*
* This example explains how to use the hand eye calibration for the case where
* the camera is stationary with respect to the robot and the calibration
* object is attached to the robot arm.
*這個示例展示了如何使用手眼標(biāo)定,這種情形用于相機(jī)與機(jī)械手基礎(chǔ)坐標(biāo)系位置固定且標(biāo)定板固定在相機(jī)的末端軸上。
* In this case, the goal of the hand eye calibration
* is to determine two unknown poses:
*在這種情況下,手眼標(biāo)定目標(biāo)是確定一下兩個位置姿態(tài)。
* - the pose of the robot base in the coordinate system
* of the camera (BaseInCamPose).
*基于相機(jī)坐標(biāo)系的機(jī)械手基礎(chǔ)坐標(biāo)系姿態(tài)
* - the pose of the calibration object in the coordinate system of the
* tool (CalObjInToolPose)
*基于相機(jī)末端(工具)坐標(biāo)系的標(biāo)定板姿態(tài)
* Theoretically, as input the method needs at least 3 poses of the
* calibration object in the camera coordinate system and the corresponding
* poses of the robot tool in the coordinate system of the
* robot base. However it is recommended to use at least 10 Poses.
*理論上至少需要三個基于相機(jī)坐標(biāo)系系統(tǒng)下標(biāo)定物的姿態(tài)和基于機(jī)器人坐標(biāo)系機(jī)器人末端工作坐標(biāo)系的姿態(tài)。
*但建議至少使用10個姿態(tài)。
* The poses of the calibration object are obtained from images of the
* calibration object recorded with the stationary camera.
*標(biāo)定板的姿態(tài)是從靜止相機(jī)拍攝的標(biāo)定板圖像內(nèi)獲得的。
* The calibration object is moved by the robot with respect to the camera.
*標(biāo)定板相對于相機(jī)由機(jī)器人移動。
* To obtain good calibration results, it its essential to position
* the calibration object with respect to the camera so that the object appears
* tilted in the image.
*為了獲得良好的標(biāo)定效果,標(biāo)定物相對于相機(jī)其圖像要傾斜(旋轉(zhuǎn))一些。
* After the hand eye calibration, the computed transformations are
* extracted and used to compute the pose of the calibration object in the
* camera coordinate system.
*在手眼標(biāo)定后,提取計算出的變換矩陣用于計算在相機(jī)坐標(biāo)系系統(tǒng)中計算標(biāo)定對象的姿態(tài)。
dev_update_off ()
* Directories with calibration images and data files
*以下是圖像和數(shù)據(jù)文件
ImageNameStart := '3d_machine_vision/handeye/stationarycam_calib3cm_'
DataNameStart := 'handeye/stationarycam_'
NumImages := 17
* Read image
read_image (Image, ImageNameStart + '00')
get_image_size (Image, Width, Height)
* Open window 打開窗口
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_line_width (2)
dev_set_draw ('margin')
dev_display (Image)
* Set font 設(shè)置字體
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* Load the calibration plate description file.
* Make sure that the file is in the current directory,
* the HALCONROOT/calib directory, or use an absolut path
*加載標(biāo)定板說明文件,確保文件在正確的目錄內(nèi)或使用絕對路徑
CalTabFile := 'caltab_30mm.descr'
* Read the initial values for the internal camera parameters
*讀取相機(jī)的內(nèi)參
read_cam_par (DataNameStart + 'start_campar.dat', StartCamParam)
* Create the calibration model for the hand eye calibration
*創(chuàng)建一個標(biāo)定模型用于手眼標(biāo)定
create_calib_data ('hand_eye_stationary_cam', 1, 1, CalibDataID)
*給標(biāo)定模板設(shè)置相機(jī)參數(shù) 面陣相機(jī)
set_calib_data_cam_param (CalibDataID, 0, 'area_scan_division', StartCamParam)
*給標(biāo)定模板設(shè)置標(biāo)定板文數(shù)據(jù)
set_calib_data_calib_object (CalibDataID, 0, CalTabFile)
*設(shè)置標(biāo)定數(shù)據(jù)
*設(shè)置手眼校準(zhǔn)過程中使用的優(yōu)化方法。如果設(shè)置了dataValue='linear',則使用線性方法進(jìn)行手眼校準(zhǔn)。
*如果設(shè)置了dataValue='非線性',則將使用非線性方法進(jìn)行手眼校準(zhǔn)(有關(guān)詳細(xì)信息,請參見校準(zhǔn)手眼)。
set_calib_data (CalibDataID, 'model', 'general', 'optimization_method', 'nonlinear')
disp_message (WindowHandle, 'The calibration data model was created', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Start the loop over the calibration images 開始循環(huán)標(biāo)定圖像
for I := 0 to NumImages - 1 by 1
read_image (Image, ImageNameStart + I$'02d')
* Search for the calibration plate, extract the marks and the
* pose of it, and store the results in the calibration data model of the
* hand-eye calibration
*搜索標(biāo)定板,提取標(biāo)記和位置,并將結(jié)果存儲在手眼標(biāo)定的數(shù)據(jù)模板中
find_calib_object (Image, CalibDataID, 0, 0, I, [], [])
get_calib_data_observ_contours (Caltab, CalibDataID, 'caltab', 0, 0, I)
* get_calib_data_observ_contours (Caltab, CalibDataID, 'marks', 0, 0, I)
get_calib_data_observ_points (CalibDataID, 0, 0, I, RCoord, CCoord, Index, CalObjInCamPose)
* Visualize the extracted calibration marks and the estimated pose (coordinate system)
*顯示提取到的標(biāo)定mark點(diǎn)和估算姿態(tài)
dev_set_color ('green')
dev_display (Image)
dev_display (Caltab)
dev_set_color ('yellow')
disp_cross (WindowHandle, RCoord, CCoord, 6, 0)
dev_set_colored (3)
disp_3d_coord_system (WindowHandle, StartCamParam, CalObjInCamPose, 0.01)
* Read pose of tool in robot base coordinates (ToolInBasePose)
*在機(jī)械手基礎(chǔ)坐標(biāo)系中讀取末端工具坐標(biāo)系的姿態(tài)
read_pose (DataNameStart + 'robot_pose_' + I$'02d' + '.dat', ToolInBasePose)
* Set the pose tool in robot base coordinates in the calibration data model
*給標(biāo)定數(shù)據(jù)模板設(shè)置基于機(jī)械手基礎(chǔ)坐標(biāo)系下的工具姿態(tài)
set_calib_data (CalibDataID, 'tool', I, 'tool_in_base_pose', ToolInBasePose)
* Uncomment to inspect visualization
* disp_message (WindowHandle, 'Extracting data from calibration image ' + (I + 1) + ' of ' + NumImages, 'window', -1, -1, 'black', 'true')
* disp_continue_message (WindowHandle, 'black', 'true')
* stop ()
endfor
disp_message (WindowHandle, 'All relevant data has been set in the calibration data model', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Perform hand-eye calibration 進(jìn)行手眼標(biāo)定
* Internally before performing the hand-eye calibration the cameras are calibrated
* and the calibrated poses of the calibration object in the camera are used.
*在進(jìn)行手眼校準(zhǔn)之前,對相機(jī)進(jìn)行內(nèi)部校準(zhǔn),并使用相機(jī)中校準(zhǔn)對象的校準(zhǔn)姿態(tài)。
dev_display (Image)
disp_message (WindowHandle, 'Performing the hand-eye calibration', 'window', 12, 12, 'black', 'true')
*進(jìn)行手眼校準(zhǔn)之前,得到優(yōu)化的平均殘差
calibrate_hand_eye (CalibDataID, Errors)
* Query the camera parameters and the poses 查詢相機(jī)參數(shù)和姿勢
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParam)
* Get poses computed by the hand eye calibration 通過手眼標(biāo)定計算出姿勢
get_calib_data (CalibDataID, 'camera', 0, 'base_in_cam_pose', BaseInCamPose)
get_calib_data (CalibDataID, 'calib_obj', 0, 'obj_in_tool_pose', ObjInToolPose)
dev_get_preferences ('suppress_handled_exceptions_dlg', PreferenceValue)
dev_set_preferences ('suppress_handled_exceptions_dlg', 'true')
try
* Store the camera parameters to file 將相機(jī)參數(shù)存儲到文件
write_cam_par (CamParam, DataNameStart + 'final_campar.dat')
* Save the hand eye calibration results to file 將手眼標(biāo)定結(jié)果保存到文件
write_pose (BaseInCamPose, DataNameStart + 'final_pose_cam_base.dat')
write_pose (ObjInToolPose, DataNameStart + 'final_pose_tool_calplate.dat')
catch (Exception)
* Do nothing
endtry
dev_set_preferences ('suppress_handled_exceptions_dlg', PreferenceValue)
* Display calibration errors of the hand-eye calibration
Message := 'Quality of the results: root mean square maximum'
Message[1] := 'Translation part in meter: ' + Errors[0]$'6.4f' + ' ' + Errors[2]$'6.4f'
Message[2] := 'Rotation part in degree: ' + Errors[1]$'6.4f' + ' ' + Errors[3]$'6.4f'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* For the given camera, get the corresponding pose indices and calibration object indices
*對于給定的相機(jī),獲取相應(yīng)的姿態(tài)指數(shù)和標(biāo)定對象指數(shù)。
query_calib_data_observ_indices (CalibDataID, 'camera', 0, CalibObjIdx, PoseIds)
* Compute the pose of the calibration object in the camera coordinate
* system via calibrated poses and the ToolInBasePose and visualize it.
*通過標(biāo)定姿態(tài)和工具基本姿態(tài)計算相機(jī)坐標(biāo)系中校準(zhǔn)對象的姿態(tài),并將其可視化。
for I := 0 to NumImages - 1 by 1
read_image (Image, ImageNameStart + I$'02d')
* Obtain the pose of the tool in robot base coordinates used in the calibration.
* The index corresponds to the index of the pose of the observation object.
*在校準(zhǔn)中使用的機(jī)器人基礎(chǔ)坐標(biāo)中獲取工具的姿態(tài)。
*該索引對應(yīng)于觀測對象姿態(tài)的索引。
get_calib_data (CalibDataID, 'tool', PoseIds[I], 'tool_in_base_pose', ToolInBasePose)
dev_display (Image)
* Compute the pose of the calibration plate with respect to the camera and visualize it
* 計算校準(zhǔn)板相對于攝像機(jī)的姿態(tài)并將其可視化
calc_calplate_pose_stationarycam (ObjInToolPose, BaseInCamPose, ToolInBasePose, CalObjInCamPose)
dev_set_colored (3)
disp_3d_coord_system (WindowHandle, CamParam, CalObjInCamPose, 0.01)
Message := 'Using the calibration results to display the'
Message[1] := 'coordinate system in image ' + (I + 1) + ' of ' + NumImages
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
if (I < NumImages - 1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
* Clear the data model
clear_calib_data (CalibDataID)
*
* After the hand-eye calibration the computed pose
* BaseInCamPose can be used in robotic grasping applications.
* If the tool coordinate system is placed at the gripper
* and a object detected at ObjInCamPose shall be grasped,
* the pose of the detected object relative
* to the robot base coordinate system has to be computed.
pose_invert (BaseInCamPose, CamInBasePose)
pose_compose (CamInBasePose, CalObjInCamPose, ObjInBasePose)
轉(zhuǎn)載于:https://www.cnblogs.com/yangmengke2018/p/9743334.html
總結(jié)
以上是生活随笔為你收集整理的手眼标定eye-to-hand 示例:handeye_stationarycam_calibration的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Go实现的秒杀系统
- 下一篇: 浅谈瀑布流