dev_close_window()
* Image Acquisition 01: Code generated by Image Acquisition 01
read_image (Image, 'C:/Users/Administrator/Pictures/车牌.jpg')
get_image_size(Image, Width, Height)
*1)打开一个640*480窗口,并显示这张图
dev_open_window_fit_size (0, 0, 640, 480, -1, -1, WindowHandle)
dev_display(Image)
*dev_set_window_extents改变图形窗口的大小,左上角坐标和右下角坐标
dev_set_window_extents (0, 0, 640, 480)
*dev_set_part用于设置图形窗口中要显示的图像部分。 参数Row1和Column1指定左上角,Row2和Column2指定要显示的图像部分的右下角
dev_set_part (0, 0, 1071, 1919)
dev_display (Image)
disp_message(WindowHandle, '宽'+Width+'高'+Height,100,12, 12, 'white', 'true')
stop()
*2)识别结果用绿色字体显示在窗口左上角位置
decompose3(Image, ImageR, ImageG, ImageB)
trans_from_rgb(ImageR, ImageG, ImageB, ImageResult1, ImageResult2, ImageResult3, 'hsv')
*很关键,必须翻转图像,否则识别不出正确的字符
invert_image(ImageB, ImageInvert)
threshold (ImageB, Regions, 126, 255)
connection(Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [656.47,467.97], [678.06,574.73])
connection(SelectedRegions, ConnectedRegions1)
stop()
*排序,选特征,列Colum替代行row
sort_region(ConnectedRegions1, SortedRegions, 'character', 'true', 'column')
connection(SortedRegions, ConnectedRegions2)
*选用halcon自带字库,0-9A-Z_NoRej,0-9和A-Z,非标准
read_ocr_class_mlp('Industrial_0-9A-Z_NoRej.omc',OCRHandle)
do_ocr_multi_class_mlp(ConnectedRegions2, ImageInvert, OCRHandle, Class, Confidence)
dev_display(Image)
disp_message(WindowHandle, Class, 'Image', 12, 12, 'green', 'true')