Halcon OCR学习-读取

read_image (Image, 'C:/Users/Administrator/Desktop/221.jpg')
gen_empty_obj (EmptyObject)
Word:=['你','好','中','国']
*创建训练文件,将文字图像与文字分类标识关联,保存到训练文件中,训练文件后缀名
*为trf,主要用到函数为append_ocr_trainf。
for Index := 1 to 4 by 1
    draw_rectangle1 (3600, Row1, Column1, Row2, Column2)
    gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
    reduce_domain (Image, Rectangle, ImageReduced)
    threshold (ImageReduced, Region, 128, 255)
    closing_circle (Region, RegionOpening, 2)
    *concat_obj (EmptyObject, RegionOpening, EmptyObject)
     append_ocr_trainf (RegionOpening, Image, Word[Index-1], 'C:/Users/Administrator/Desktop/Halcon练习/匹配定位/word.trf')
endfor
*训练OCR分类器,Halcon支持BOX分类器、神经网络分类器(MLP)和支持向量机分
*类器(SVM),由于后两者比前者更加强大,推荐使用后两者。训练分类器非常简单
*首先调用create_ocr_class_mlp或create_ocr_class_svm创建分类器,然后调用
*trainf_ocr_class_mlp或trainf_ocr_class_svm训练分类器,
*用write_ocr_class_mlp或write_ocr_class_svm可以保存训练结果。
read_ocr_trainf_names ('C:/Users/Administrator/Desktop/Halcon练习/匹配定位/word.trf', CharacterNames, CharacterCount)
create_ocr_class_mlp (12, 15, 'constant', 'default', CharacterNames, 80, 'none', 10, 42, OCRHandle)
trainf_ocr_class_mlp (OCRHandle, 'C:/Users/Administrator/Desktop/Halcon练习/匹配定位/word.trf', 200, 1, 0.01, Error, ErrorLog)
write_ocr_class_mlp (OCRHandle, 'C:/Users/Administrator/Desktop/Halcon练习/匹配定位/word.omc')

read_image (Image1, 'C:/Users/Administrator/Desktop/221.jpg')
draw_rectangle1 (3600, Row11, Column11, Row21, Column21)
gen_rectangle1 (Rectangle1, Row11, Column11, Row21, Column21)
reduce_domain (Image1, Rectangle1, ImageReduced1)
threshold (ImageReduced1, Region1, 128, 255)
closing_circle (Region1, RegionOpening1, 2)
*将像素相连的区域合并成一个单元
connection (RegionOpening1, ConnectedRegions)
sort_region (ConnectedRegions, SortedRegions2, 'upper_left', 'true', 'column')
*对检测图像进行字符分类
do_ocr_multi_class_mlp (SortedRegions2, ImageReduced1, OCRHandle, Class, Confidence)

模板

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页