七.图像校正Halcon

1.get_image_size(Image : : : Width, Height)

返回图像的尺寸。

2.parameters_image_to_world_plane_centered (CamParam, Pose, CenterRow, CenterCol, WidthMappedImage, HeightMappedImage, ScaleForCenteredImage, PoseForCenteredImage)

Halcon内部程序,输出为图像的比率和姿态。

3.gen_image_to_world_plane_map( : Map : CameraParam, WorldPose, WidthIn, HeightIn, WidthMapped, HeightMapped, Scale, MapType : )

产生一个投影映射,该映射描述图像平面与Z=O的世界平面之间的关系,输出为图像MAP,是一个多通道的图像

包含了映射数据。

4.map_image(Image, Map : ImageMapped : : ) 

利用映射变换校正图像,输出为矫正后的图像。

5.image_to_world_plane(Image : ImageWorld : CameraParam, WorldPose, Width, Height, Scale, Interpolation : ) 

把校正后的图像转换到Z=0的世界平面。

6.image_points_to_world_plane( : : CameraParam, WorldPose, Rows, Cols, Scale : X, Y)  

把图像上的点转换到Z=0的世界平面,输出为点坐标。

* This program provides procedures for the determination of the
* parameters Pose and Scale of the operators image_to_world_plane
* and gen_image_to_world_plane_map.
*
* Read the image
ImgPath := '3d_machine_vision/calib/'
read_image (Image, ImgPath+'caliper_01')
* Set the camera parameters for the image
CamParam := [0.0160728,-631.843,7.40077e-006,7.4e-006,326.369,246.785,652,494]
Pose := [-41.2272,26.763,398.682,359.655,359.202,322.648,0]
* Reopen the window appropriately
get_image_size (Image, WidthOriginalImage, HeightOriginalImage)
dev_open_window_fit_image (Image, 0, 0, WidthOriginalImage, HeightOriginalImage, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_color ('red')
WidthMappedImage := 652
HeightMappedImage := 494
* Transform the image such that a given point appears in the
* center of the rectified image and the the scale of the rectified image
* is similar to the scale of the original image (in the surroundings
* of the given point)
* Define the point that will appear in the center of the rectified image
dev_display (Image)
disp_message (WindowHandle, 'Define the center of the mapped image', 'window', 12, 12, 'white', 'false')
get_mbutton (WindowHandle, CenterRow, CenterCol, Button)
* Determine scale and pose such that the given point appears
* in the center of the rectified image and that the
* scale of the two images is similar (in the surroundings
* of the given point).
parameters_image_to_world_plane_centered (CamParam, Pose, CenterRow, CenterCol, WidthMappedImage, HeightMappedImage, ScaleForCenteredImage, PoseForCenteredImage)
* Rectify the image
gen_image_to_world_plane_map (Map, CamParam, PoseForCenteredImage, WidthOriginalImage, HeightOriginalImage, WidthMappedImage, HeightMappedImage, ScaleForCenteredImage, 'bilinear')
map_image (Image, Map, ImageMapped)
dev_open_window_fit_image (ImageMapped, 0, 0, WidthMappedImage, HeightMappedImage, WindowHandleMapped)
set_display_font (WindowHandleMapped, 14, 'mono', 'true', 'false')
dev_set_color ('red')
dev_display (ImageMapped)
* In case, only one image has to be mapped, the operator
* image_to_world_plane can be used instead of the operators
* gen_image_to_world_plane_map together with map_image.
image_to_world_plane (Image, ImageMapped, CamParam, PoseForCenteredImage, WidthMappedImage, HeightMappedImage, ScaleForCenteredImage, 'bilinear')
* Display the center point
image_points_to_world_plane (CamParam, PoseForCenteredImage, CenterRow, CenterCol, ScaleForCenteredImage, CenterX, CenterY)
disp_cross (WindowHandleMapped, CenterY, CenterX, 6, rad(45))
disp_message (WindowHandleMapped, 'The selected point appears in the center', 'window', 12, 12, 'white', 'false')
disp_message (WindowHandleMapped, 'of the rectified image', 'window', 36, 12, 'white', 'false')
disp_continue_message (WindowHandleMapped, 'black', 'true')
stop ()
*
* Now determine scale and pose such that the entire image
* fits into the rectified image.
parameters_image_to_world_plane_entire (Image, CamParam, Pose, WidthMappedImage, HeightMappedImage, ScaleForEntireImage, PoseForEntireImage)
* Rectify the image
image_to_world_plane (Image, ImageMapped, CamParam, PoseForEntireImage, WidthMappedImage, HeightMappedImage, ScaleForEntireImage, 'bilinear')
dev_clear_window ()
dev_display (ImageMapped)
disp_message (WindowHandleMapped, 'The entire image is visible in the rectified image', 'window', -1, -1, 'white', 'false') 

你可能感兴趣的:(Halcon)