Blob分析之bottle.hdev

* 分割讀取啤酒瓶子上的數字
* bottle.hdev: Segment and read numbers on a beer bottle
* 第0步
* Step 0: Preparations
*定義字體名稱,用來讀取瓶子上的數據/或者可以這麼理解,定義瓶子上數據的字體
* Specify the name of the font to use for reading the date on the bottle.
*用訓練好的0-9通用字體是最簡單的。如果已經運行過這個程式,你可以第二行名稱,是用這個項目訓練的字體
* It is easiest to use the pre-trained font Universal_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.
FontName := ‘Universal_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)
*顯示’Press F5 to continiue’這個資訊
disp_continue_message (WindowID, ‘black’, ‘true’)
stop ()
* 創建自動文字讀取器以及設置一些參數
* Create Automatic Text Reader and set some parameters
*創建文字讀取器
create_text_model_reader (‘auto’, FontName, TextModel)
* The printed date has a significantly higher stroke width
*設置文字讀取參數的最小寬度
set_text_model_param (TextModel, ‘min_stroke_width’, 6)
*最佳日期(表示多級之前引用是最佳的)有一個特殊和已知的結構
* The “best before” date has a particular and known structure
*設置文字組成格式,’2 2 2’便是由三段數字構成,中間由空白或者分隔符分開 ’19’表示沒有分隔符或者空白
set_text_model_param (TextModel, ‘text_line_structure’, ‘2 2 2’)
* 讀取最佳日期
* Read the “best before” date
find_text (Bottle, TextModel, TextResultID)
* 獲取最佳日期文字並顯示
* Display the segmentation results
get_text_object (Characters, TextResultID, ‘all_lines’)
*顯示瓶子影像
dev_display (Bottle)
*顯示讀取到的字元
dev_display (Characters)
stop ()
*顯示讀取到的結果
* Display the reading results
*獲取文字結果
get_text_result (TextResultID, ‘class’, Classes)
*求區域面積和中心坐標
area_center (Characters, Area, Row, Column)
*顯示讀取到的文字資訊
disp_message (WindowID, Classes, ‘image’, 80, Column – 3, ‘green’, ‘false’)
* 釋放記憶體
* Free memory
*清楚文字結果
clear_text_result (TextResultID)
*清楚Text模型
clear_text_model (TextModel)