*
* 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)
来源:oschina
链接:https://my.oschina.net/u/4281901/blog/3873719