這是一個很久以前的微博網友寫的,現在的halcon運行有問題,因為已經沒有parameters_image_to_world_plane_centered這個函數了,知道現在版本替換它的函數的朋友麻煩告知一下,萬分感謝
本文出處:http://blog.sina.com.cn/s/blog_442bfe0e0100yjce.html#commonComment
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')