Bootstrap

Halcon机器视觉仿射变换

1:Halcon_图像读取

2:Halcon_车牌定位

3:Halcon_扣出车牌

4:Halcon_基于扣除的字符识别车牌

一:Halcon_图像读取

*读取图像
dev_close_window ()
read_image (Image, 'E:/u=1490048951,3458980489&fm=173&app=49&f=JPEG.jfif')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)

二:*Halcon_处理图像

rgb1_to_gray (Image, GrayImage)
select_shape (SelectedRegions, SelectedRegions1, ['area','row'], 'and', [39298.7,136.16], [50000,303.73])
threshold (GrayImage, Regions, 0, 110)
connection (Regions, ConnectedRegions)
select_shape (SelectedRegions, SelectedRegions, ['area','row'], 'and', [1958.11,136.16], [50000,303.73])

三:Halcon_处理图像——转正图像

shape_trans (SelectedRegions, RegionTrans, 'convex')
area_center (RegionTrans, Area, Row, Column)
orientation_region (RegionTrans, Phi)
vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
affine_trans_image (GrayImage, ImageAffineTrans, HomMat2D, 'constant', 'false')
reduce_domain (ImageAffineTrans, RegionTrans, ImageReduced)

四:Halcon_开始识别——车牌图像预处理

rgb1_to_gray (ImageReduced, GrayImage1)
threshold (GrayImage1, Region, 128, 255)
erosion_rectangle1 (Region, RegionErosion, 2, 2)
opening_rectangle1 (RegionErosion, RegionOpening,2.5,2.5)
connection (RegionOpening, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions2, 'area', 'and', 800, 1700)
sort_region (SelectedRegions2, SortedRegions, 'character', 'false', 'column')
select_obj (SelectedRegions2, ObjectSelected, 1)

五:Halcon_识别字符+显示检测到的车牌号

invert_image (GrayImage1, ImageInvert)
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, ImageInvert, OCRHandle, Class, Confidence)
set_display_font (WindowHandle, 30, 'mono', 'true', 'false')
dev_set_color ('red')
for Index := 0 to |Class|-1 by 1
    if (Class[Index]=='N')
        set_tposition (WindowHandle, 30, 460-65*Index)
        write_string (WindowHandle, 'A')
        break
    endif
    set_tposition (WindowHandle, 30, 460-65*Index)
    write_string (WindowHandle, Class[Index])
endfor

最后检测结果



算子使用的并不是很熟练,若有问题请大家指正----一位实习半年的机器视觉小白👼

;