halcon ocr 生成样本变体 |
您所在的位置:网站首页 › halcon函数doocrmulticlassmlp › halcon ocr 生成样本变体 |
Halcon OCR 总结 By 17003 步骤: 1. 创建训练文件, 将文字图像与文字分类标识关联, 保存到训练文件中, 训练文件后缀名 为 trf ,主要用到函数为 append_ocr_trainf 。 2. 训练 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 可以保存训练结果。 3. 测试分类器,读入图像,如要文字不是水平,应将其旋转成水平,可以使用以下函数: text_line_orientation 计算文字倾角, rotate_image 旋转图像。注意前者使用的是弧度, 后角使用的是度。分割文字。读取分类器 read_ocr_class_mlp ,即读取训练分类器的结 果。使用 do_ocr_multi_class_mlp 对文字进行识别。 参考以下实例: 为方便起见, 这里将三个步骤放在一个实例里, 也可以分别将三个步骤保存成三个独立的程 序。 * 1 创建训练文件 *1.1 分割字符 dev_close_window() read_image(Image,'F:/ 学习资料 /Halcon 工程 /ocr-train.bmp') get_image_size(Image, Width, Height) dev_open_window(0, 0, Width, Height, 'black', WindowHandle) dev_display(Image) threshold(Image, Region, 0, 100) connection(Region, ConnectedRegions) sort_region (ConnectedRegions, SortedRegions, 'upper_left', 'true', 'column') count_obj(SortedRegions, Number) for Index := 1 to Number by 1 dev_clear_window() select_obj(SortedRegions, SingleWord, Index) dev_display(SingleWord) stop() endfor *1.2 文字分类标识 words:=['a','b','c','d','e','f','g'] *1.3 创建训练文件 TrainFile:='words.trf' dev_set_check('~give_error') delete_file(TrainFile) dev_set_check('~give_error') *1.4 将图像字符与字符标识关联,保存到训练图像中 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |