HALCON示例:BOTTLE.HDEV 光學字符識別(分割OCR)


*
* bottle.hdev: Segment and read numbers on a beer bottle 分割讀取啤酒瓶上的數字
*
* Step 0: Preparations
* Specify the name of the font to use for reading the date on the bottle.
* It is easiest to use the pre-trained font Industrial_0-9_NoRej. If you
* have run the program bottlet.hdev in this directory, you can activate
* the second line to use the font trained with this program.
*這個示例指定讀取啤酒瓶上數字字體的名稱。
*用事先訓練好的Industrial_0-9_NoRej很容易識別字體。
*如果在同一目錄下運行了bottlet.hdev示例,可以在這個程序中激活第二行使用。
* FontName := 'Industrial_0-9_NoRej'
FontName := 'bottle'
*
* Step 1: Segmentation
dev_update_window ('off')
read_image (Bottle, 'bottle2')
get_image_size (Bottle, Width, Height)
dev_close_window ()
dev_open_window (0, 0, 2 * Width, 2 * Height, 'black', WindowID)
set_display_font (WindowID, 16, 'mono', 'true', 'false')
dev_display (Bottle)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*
* Create Automatic Text Reader and set some parameters
*OCR字符識別————Segmentation分割 創建文本讀取模型
create_text_model_reader ('auto', FontName, TextModel)
* The printed date has a significantly higher stroke width 打印日期具有顯著更高的筆划寬度。
*OCR字符識別————Segmentation分割 設置文本模型的參數
set_text_model_param (TextModel, 'min_stroke_width', 5)
* The "best before" date has a particular and known structure 讀不懂
*OCR字符識別————Segmentation分割 設置文本模型的參數
set_text_model_param (TextModel, 'text_line_structure', '2 2 2')
*
* Read the "best before" date
*OCR字符識別————Segmentation分割 利用TextModel指定的文本模型對圖像中的文本進行分割,並返回分割結果
find_text (Bottle, TextModel, TextResultID)
*
* Display the segmentation results
*OCR字符識別————Segmentation分割 獲取由算子find_text返回的文本
get_text_object (Characters, TextResultID, 'all_lines')
dev_display (Bottle)
dev_display (Characters)
stop ()
* Display the reading results
*OCR字符識別————Segmentation分割
*get_text_result( : : TextResultID, ResultName : ResultValue)
*獲取由算子find_text返回的文本結果的控制結果,TextResultID輸入的文本結果,Classes輸出結果
get_text_result (TextResultID, 'class', Classes)
area_center (Characters, Area, Row, Column)
for Index := 0 to |Classes| - 1 by 1
disp_message (WindowID, Classes[Index], 'image', 80, Column[Index] - 3, 'green', 'false')
endfor
*
* Free memory
*清除由句柄TextResultID指定的文本結果
clear_text_result (TextResultID)
*清除由句柄TextModel指定的文本模型
clear_text_model (TextModel)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM