浅谈计算机视觉HALCON视觉库识别车牌号
如图,使用HALCON视觉库识别车牌号,代码如下:
dev_close_window ()
read_image (Image, ‘Q:/车牌.jpg’)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, ‘black’, WindowHandle)
dev_display (Image)
*预处理
decompose3 (Image, ImageR, ImageG, ImageB)
trans_from_rgb (ImageR, ImageG, ImageB, ImageH, ImageS, ImageV, ‘hsv’)
threshold (ImageR, Regions, 0, 54)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ‘area’, ‘and’, 15536.6, 26219.5)
XCoordCorner := [88, 152, 258, 187]
YCoordCorner := [82, 366, 368, 88]
gen_cross_contour_xld (Crosses, XCoordCorner, YCoordCorner, 10, 0.785398)
dev_display (ImageR)
dev_display (Crosses)
*几何投影
hom_vector_to_proj_hom_mat2d (XCoordCorner, YCoordCorner, [1, 1, 1, 1], [80, 80, 160, 160], [80, 370, 370, 80], [1, 1, 1, 1], ‘normalized_dlt’, HomMat2D)
projective_trans_image (ImageR, TransImage, HomMat2D, ‘bilinear’, ‘false’, ‘false’)
threshold (TransImage, Regions1, 157, 238)
connection (Regions1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, [‘width’,‘height’], ‘and’, [26.1,52.341], [36.34,62.683])
sort_region (SelectedRegions1, SortedRegions, ‘character’, ‘true’, ‘row’)
*识别
invert_image (TransImage, ImageInvert)
read_ocr_class_mlp (‘Industrial_0-9A-Z_NoRej.omc’, OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, ImageInvert, OCRHandle, Class, Confidence)
disp_message (WindowHandle, Class, ‘window’, 12, 12, ‘black’, ‘true’)
clear_ocr_class_mlp (OCRHandle)
照片从网上下载的,如侵权,请联系删除。