* Image Acquisition 01: Code generated by Image Acquisition 01
dev_close_window ()
dev_open_window (0, 0,512, 512, 'black', WindowID)
dev_set_part (0, 0, 511, 511)
read_image (Image, 'E:/机器视觉/Halcon/P2.png')
get_image_size (Image, Width, Height)
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
*RGB转灰度图
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Regions, 38, 167)
fill_up (Regions, RegionFillUp)
connection (RegionFillUp, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 32194, 43322.7)
area_center (SelectedRegions, Area, Row, Column)
dev_display (Image)
disp_message (WindowID, '面积:'+Area+' '+'坐标:'+'('+Row+','+Column+')', 'window', 0, 0, 'white', 'red')
摄像头实时识别
* Image Acquisition 03: Code generated by Image Acquisition 03
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] AX USB2.0', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
dev_close_window ()
dev_open_window (0, 0,512, 512, 'black', WindowID)
while (true)
grab_image_async (Image, AcqHandle, -1)
dev_resize_window_fit_image (Image, 0, 0, -1, -1)
*RGB转灰度图
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Regions, 0, 77)
area_center (Regions, Area, Row, Column)
dev_display (Image)
disp_message (WindowID, '面积:'+Area+' '+'坐标:'+'('+Row+','+Column+')', 'window', 0, 0, 'white', 'red')
dev_clear_window ()
endwhile
close_framegrabber (AcqHandle)