超远心镜头允许以单个图像同时完成物体的顶部和侧面成像(超广角)功能。
(左)使用常规镜头检查的小瓶的侧视图。(中)使用超心镜头的顶视图。(右)在相机校准和映射后,标签的展开表面。
成像模型如下:
代码:
- *
- * This example demonstrates how to calibrate a camera
- * with a hypercentric lens and how to unroll the label of a bottle,
- * which can be used to perform various 360 degree inspection tasks.
- *
- * Prepare window.
- dev_close_window ()
- dev_open_window (0, 0, 700, 700, 'black', WindowHandle)
- set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
- dev_update_off ()
- *
- * 1. Calibrate the camera (offline).
- *
- * Specify the calibration object.
- CalTabName := 'calplate_40mm.cpd'
- * Specify the initial camera parameters.
- ImageWidth := 1970
- ImageHeight := 1970
- gen_cam_par_area_scan_hypercentric_polynomial (0.008, 0, 0, 0, 0, 0, 3.1e-006, 3.1e-006, ImageWidth / 2, ImageHeight / 2, ImageWidth, ImageHeight, CameraParamStart)
- * Create a calibration data model.
- create_calib_data ('calibration_object', 1, 1, CalibDataID)
- set_calib_data_cam_param (CalibDataID, 0, [], CameraParamStart)
- set_calib_data_calib_object (CalibDataID, 0, CalTabName)
- *
- get_window_param (WindowHandle, 'flush', Flush)
- set_window_param (WindowHandle, 'flush', 'false')
- for J := 1 to 25 by 1
- * Read the calibration image.
- read_image (Image, 'calib/calib_hypercentric_' + J$'02')
- * Find the calibration object in the image.
- find_calib_object (Image, CalibDataID, 0, 0, J, [], [])
- * Visualize the extracted marks.
- get_calib_data_observ_contours (Ellipses, CalibDataID, 'marks', 0, 0, J)
- dev_display (Image)
- dev_set_color ('green')
- dev_display (Ellipses)
- dev_disp_text ('Calibration image ' + J + ' (of 25) and extracted marks', 'window', 'top', 'left', 'black', [], [])
- flush_buffer (WindowHandle)
- endfor
- set_window_param (WindowHandle, 'flush', Flush)
- * Perform the camera calibration.
- calibrate_cameras (CalibDataID, Error)
- * Query the calibrated camera parameters.
- get_calib_data (CalibDataID, 'camera', 0, 'params_labels', CameraParamLabels)
- get_calib_data (CalibDataID, 'camera', 0, 'params', CameraParam)
- * Display the camera parameters.
- display_camera_parameters (CameraParamStart, CameraParam, Error, CameraParamLabels$'-5', WindowHandle)
- dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
- stop ()
- *
- * 2. Generate a map that can be used to unroll the surface
- * of a cylindrical object (offline).
- *
- read_image (Image, 'bottle_label/eye_drops_vial_hypercentric')
- dev_display (Image)
- dev_disp_text ('Top view of a vial with eye drops\nacquired with a hypercentric lens.', 'window', 'top', 'left', 'black', [], [])
- dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
- stop ()
- * Specify the radius of the cylindrical vial at its base
- * and at its circular screw cap on top.
- VialRadiusBase := 0.0112
- VialRadiusTop := 0.0034
- * Determine the pose of the vial.
- get_vial_pose (Image, CameraParam, VialRadiusBase, VialRadiusTop, WindowHandle, VialBase, VialAxis)
- stop ()
- * Create a map that unrolls the labeled surface of the vial.
- * Specify the range along the cylinder axis that should be unrolled.
- * CylinderZStart = 0 and CylinderZEnd = 0.026
- * means that the vial is unrolled from its circular bottom
- * up to a height of 2.6 centimeters.
- CylinderZStart := 0.0
- CylinderZEnd := 0.026
- CylinderUnrollAngleStart := rad(40)
- MapWidth := 1500
- MapHeight := 500
- gen_cylinder_unrolling_map (Map, CameraParam, VialBase, VialAxis, VialRadiusBase, CylinderZStart, CylinderZEnd, CylinderUnrollAngleStart, ImageWidth, ImageHeight, MapWidth, MapHeight)
- *
- * 3. Unroll the surface (online)
- *
- * Resize the window according to the size
- * of the unrolled image.
- dev_resize_window_fit_size (0, 0, MapWidth, MapHeight, -1, -1)
- * If it can be ensured that the vial always appears
- * at the same position, the map can be used in runtime images
- * to efficiently unwrap the surface of the vial.
- map_image (Image, Map, ImageMapped)
- dev_display (ImageMapped)
- dev_disp_text ('Unrolled label', 'window', 'top', 'left', 'black', [], [])
复制代码
代码位置:
- %HALCONEXAMPLES%\hdevelop\Calibration\Multi-View\calibrate_cameras_hypercentric.hdev
复制代码 |