通過學習別人的程序,個人了解到車牌識別分為如下幾個步驟:
1.讀取一張車牌照片
2.將車牌照片轉化成R、G、B、H、S、V分量
3.選取最合適的分量圖像進行閾值分割(獲取車牌在圖像中的區域)
4.打開矩形區域
5.獲取矩形區域
6.獲取矩形區域的角度
7.獲取矩形區域的中心點
8.求射頻變換的矩陣(根據極軸方向確定旋轉至0度還是180度)
9.旋轉圖像
10.從原圖中摳取當前矩形區域
11.縮小圖像區域
12.圖像灰度化
13.由於Halcon自帶字庫為白底黑字,所以將圖像灰度值翻轉
14.閾值分割出文字區域
15.消除噪點
16.砍成不同區域
17.根據中心點坐標選取區域
18.根據面積選取區域
19.區域排序
20.選取Halcon自帶字庫
21.識別文字
22.顯示原圖
23顯示字符
源碼如下:
read_image (Image, 'C:/Users/58937/Desktop/t01099427dc105a338f.jpg')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image)
decompose3 (Image, Red, Green, Blue)
trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
threshold (Saturation, Regions, 182, 255)
opening_rectangle1 (Regions, RegionOpening, 6,6)
*因為是有角度的矩形所以用rectangle2
shape_trans (RegionOpening, RegionTrans, 'rectangle2')
*區域的角度和中心點
orientation_region (RegionTrans, Phi)
area_center (RegionTrans, Area, Row, Column)
*注意求解角度的極軸方向
vector_angle_to_rigid (Row, Column, Phi, Row, Column, rad(180), HomMat2D)
*旋轉,摳圖,縮小
affine_trans_image (Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
affine_trans_region (RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
reduce_domain (ImageAffinTrans, RegionAffineTrans, ImageReduced)
*字符分割
rgb1_to_gray (ImageReduced, GrayImage)
*翻轉圖像灰度值
invert_image (GrayImage, ImageInvert)
threshold (GrayImage, Regions1, 62, 255)
opening_rectangle1 (Regions1, RegionOpening1, 3,3)
*砍
connection (RegionOpening1, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'row', 'and', 108,119)
select_shape (SelectedRegions1, SelectedRegions, 'area', 'and', 80,99999)
*進行字符排序從左到右
sort_region (SelectedRegions, SortedRegions, 'first_point', 'true', 'column')
*halcon自帶字庫
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
*識別
do_ocr_multi_class_mlp (SortedRegions, ImageInvert, OCRHandle, Class, Confidence)
dev_display (Image)
disp_message (WindowHandle,Class, 'image', 0, 0, 'red', 'false')