read_image(Image, 'D:/图片/视觉检测图片/15.jpg')
rgb1_to_gray(Image, GrayImage)
FontName := 'Universal_0-9_NoRej'
get_image_size(GrayImage, Width, Height)
dev_close_window()
dev_open_window(0, 0, Width/4, Height/4, 'black', WindowHandle)
dev_display(GrayImage)
*获取文本方向
text_line_orientation (GrayImage, Image, 48, rad(-90), rad(90), OrientationAngle)
*旋转摆正图像
rotate_image (GrayImage, ImageRotate, -OrientationAngle / rad(180) * 180, 'constant')
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*自动阅读文本字符
create_text_model_reader('auto', 'Universal_Rej.occ', TextModel)
*设置字符样式参数
set_text_model_param(TextModel, 'dot_print_max_dot_gap', 8)
set_text_model_param (TextModel, 'dot_print_min_char_gap', 1)
find_text (ImageRotate, TextModel, TextResultID)
*获取字符对象
get_text_object (Characters, TextResultID, 'all_lines')
union1(Characters, RegionUnion)
dev_display (ImageRotate)
dev_display (Characters)
gen_rectangle1 (Rectangle1, 915, 357, 1050, 650)
intersection(Rectangle1, RegionUnion, RegionIntersection)
opening_circle(RegionIntersection, RegionOpening, 3.5)
connection(RegionOpening, ConnectedRegions)
sort_region(ConnectedRegions, SortedRegions, 'first_point', 'true', 'row')
read_ocr_class_mlp ('DotPrint_NoRej', OCRHandle)
count_obj(SortedRegions, Number2)
Charnum:=[]
set_display_font(WindowHandle,20 , 'mono', 'true', 'false')
for i :=1 to Number2 by 1
*选择对象
select_obj(SortedRegions, ObjectSelected, i)
*识别字体
do_ocr_single_class_mlp(ObjectSelected, ConnectedRegions,OCRHandle , 1, Class, Confidence)
Charnum:=[Charnum,Class]
endfor
* Display the reading results
get_text_result (TextResultID, 'class', Classes)
area_center (Characters, Area, Row, Column)
disp_message (WindowHandle, Classes, 'image', 80, Column - 3, 'green', 'false')