您好,登錄后才能下訂單哦!
一、待識別字符的圖像:
二、運行環境:
Halcon-12.0
三、代碼如下:
read_image (Image, 'C:/Users/研發/Desktop/捕獲.PNG')
*縮小定義域
draw_rectangle1 (3600, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (Image, Rectangle, Image)
*增強孤立點或團狀缺陷,金屬上雕刻字符的圖像,需要此算子處理后,才能容易的分割出來字符
gray_range_rect (Image, ImageResult, 7, 7)
*圖像取反,字符識別特定是識別亮背景下的暗字符
invert_image (ImageResult, ImageResult)
threshold (ImageResult, Region, 0, 140)
*閉運算,填補細小孔洞
closing_rectangle1 (Region, RegionClosing, 2, 2)
connection (RegionClosing, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 500, 99999)
*將區域按照自定義大小分開,40,100表示字符大小(矩形)
partition_rectangle (SelectedRegions, Partitioned, 40,100)
*smallest_rectangle1 (Partitioned, Row11, Column11, Row21, Column21)
*gen_rectangle1 (Rectangle1, Row11, Column11, Row21, Column21)
sort_region (Partitioned, SortedRegions, 'first_point', 'true', 'column')
*根據字符類型選擇合適的文件,也可以自己訓練文件(可參照本人另一篇博客:Halcon字符識別)
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
count_obj (SortedRegions, Number)
*循環識別單個字符
for Index:=1 to Number by 1
select_obj (SortedRegions, ObjectSelected, Index)
do_ocr_multi_class_mlp (ObjectSelected, ImageResult,OCRHandle, Class, Confidence)
endfor
clear_ocr_class_mlp (OCRHandle)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。