Halcon vector_angle_to_rigid算子運用之車牌識別

效果如圖所示:車牌圖片來源網絡,有對號牌做處理,如有雷同,純屬巧合!

Halcon代碼如下:


dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Car, 'D:/Camera/test/image/car3.jpg')
decompose3 (Car, R, G, B)
trans_from_rgb (R, G, B, H, S, V, 'hsv')
* emphasize (S, ImageEmphasize, 7, 7, 5)
invert_image (S, ImageInvert)
threshold (ImageInvert, Regions1, 0, 137)
fill_up (Regions1, RegionFillUp1)
connection (RegionFillUp1, ConnectedRegions2)
select_shape (ConnectedRegions2, SelectedRegions1, 'area', 'and', 14935.1, 74489.8)
shape_trans (SelectedRegions1, RegionTrans, 'convex')
area_center (RegionTrans, Area, Row, Column)
orientation_region (RegionTrans, Phi)
vector_angle_to_rigid (Row, Column, Phi, Row, Column, rad(180), HomMat2D)
*  affine_trans_image (ImageReduced, ImageAffineTrans, HomMat2D, 'constant', 'false')
 affine_trans_region (RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
 
 affine_trans_image (Car, CarAffineTrans, HomMat2D, 'constant', 'false')
 
 reduce_domain (CarAffineTrans, RegionAffineTrans, ImageReduced)
 
 rgb1_to_gray (ImageReduced, GrayImage)
 
 
threshold (GrayImage, Regions, 62, 249)

connection (Regions, LetterRegions)

opening_rectangle1 (LetterRegions, RegionOpening, 4, 4)


select_shape (RegionOpening, SelectedRegions, ['area','height'], 'and', [343.12,62], [2000,88.257])

sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'column')
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
invert_image (CarAffineTrans, CarImageInvert)
do_ocr_multi_class_mlp (SortedRegions, CarImageInvert, OCRHandle, Class, Confidence)
disp_message (WindowHandle, Class, 'window', 12, 12, 'black', 'true')

使用的技巧用到了圖片分割、旋轉

vector_angle_to_rigid (Row, Column, Phi, Row, Column, 3.1415, HomMat2D)

注意此處的3.1415 =數學中的π ,旋轉的角度參數爲弧度:弧度的概念=圓周/半徑,正圓的周長計算公式爲:2πR,一個半圓的角度就是 π*R/R =π;

旋轉的角度可以動態計算:例如:

targetArc:=0
pai:=3.1415926 或者rad(180)

if(Phi<pai*0.5)
    targetArc:=0
else
    targetArc:=pai
endif

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章