1 Star 0 Fork 2

shatanzhihu/CodeRecognition

forked from xiaodelea/CodeRecognition 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CodeRecognitionQingpiTrain.hdev 5.56 KB
一键复制 编辑 原始数据 按行查看 历史
<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.0" halcon_version="10.0" cs="73771779">
<procedure name="main">
<interface/>
<body>
<l>read_image (Image, 'D:/实习/图片/青啤/C1_50.bmp')</l>
<l>emphasize (Image, ImageEmphasize0, 7, 7, 5)</l>
<l>binomial_filter (ImageEmphasize0, ImageBinomial0, 7, 7)</l>
<l>threshold (ImageBinomial0, Region00, 0, 140)</l>
<l>gray_opening_shape (ImageEmphasize0, ImageOpening, 25, 25, 'rectangle')</l>
<l>threshold (ImageOpening, Region0, 0, 20)</l>
<l>opening_circle (Region0, RegionOpening0, 8)</l>
<l>connection (RegionOpening0, ConnectedRegions0)</l>
<l>select_shape (ConnectedRegions0, SelectedRegions0, ['width','height'], 'and', [80,30], [170,110])</l>
<l>select_shape_std (SelectedRegions0, SelectedRegionsStd0, 'max_area', 70)</l>
<l>count_obj (SelectedRegionsStd0, Number0)</l>
<l>if (Number0 # 1)</l>
<l> return()</l>
<l>endif</l>
<l>intersection (SelectedRegionsStd0, Region00, RegionIntersection0)</l>
<c>*旋转图像</c>
<l>smallest_rectangle2 (RegionIntersection0, Row0, Column0, Phi0, Length01, Length02)</l>
<l>tuple_deg (Phi0, Deg0)</l>
<l>rotate_image (Image, ImageRotate0, -Deg0, 'constant')</l>
<c>*处理旋转后的图像</c>
<l>emphasize (ImageRotate0, ImageEmphasize01, 7, 7, 5)</l>
<l>binomial_filter (ImageEmphasize01, ImageBinomial01, 7, 7)</l>
<l>threshold (ImageBinomial01, Region01, 0, 140)</l>
<l>gray_opening_shape (ImageEmphasize01, ImageOpening01, 25, 25, 'rectangle')</l>
<l>threshold (ImageOpening01, Region012, 0, 20)</l>
<l>opening_circle (Region012, RegionOpening01, 3.5)</l>
<l>connection (RegionOpening01, ConnectedRegions01)</l>
<l>select_shape (ConnectedRegions01, SelectedRegions01, ['width','height'], 'and', [80,30], [170,110])</l>
<l>select_shape_std (SelectedRegions01, SelectedRegionsStd01, 'max_area', 70)</l>
<l>count_obj (SelectedRegionsStd01, Number01)</l>
<l>if (Number01 # 1)</l>
<l> return()</l>
<l>endif</l>
<l>intersection (SelectedRegionsStd01, Region01, RegionIntersection01)</l>
<l>smallest_rectangle2 (RegionIntersection01, Row01, Column01, Phi01, Length011, Length012)</l>
<l>RegionPriorWidth:=74</l>
<l>RegionPriorHeight:=36</l>
<l>gen_rectangle2 (Rectangle01, Row01-1, Column01, 0, Length011, Length012+4)</l>
<c>*缩小区域</c>
<l>reduce_domain (ImageRotate0, Rectangle01, ImageReduced01)</l>
<l>emphasize (ImageReduced01, ImageEmphasize011, 7, 7, 5)</l>
<l>binomial_filter (ImageEmphasize011, ImageBinomial011, 3, 3)</l>
<c>*第一行****************************</c>
<l>gen_rectangle2 (Rectangle1, Row01-Length012/2-1, Column01, 0, Length011+4, Length012/2)</l>
<l>reduce_domain (ImageBinomial011, Rectangle1, ImageReduced1)</l>
<l>*mean_image (ImageReduced1, ImageMean1, 5, 5)</l>
<l>*dyn_threshold (ImageReduced1, ImageMean1, Region1, 50, 'light')</l>
<l>threshold (ImageReduced1, Region1, 0, 110)</l>
<l>closing_rectangle1 (Region1, RegionClosing1, 2, 50)</l>
<l>closing_circle (RegionClosing1, RegionClosing11, 3)</l>
<l>connection (RegionClosing11, ConnectedRegions1)</l>
<l>shape_trans (ConnectedRegions1, RegionTrans1, 'rectangle1')</l>
<l>partition_rectangle (RegionTrans1, Partitioned1, 15, 32)</l>
<l>select_shape (Partitioned1, SelectedRegions1, ['area','width','height'], 'and', [100,5,20], [700,25,40])</l>
<l>intersection (SelectedRegions1, Region1, RegionIntersection1)</l>
<c>*选中字符</c>
<c>*排序</c>
<l>sort_region (RegionIntersection1, SortedRegions1, 'first_point', 'true', 'column')</l>
<l>*FontName:='Industrial_0-9.omc'</l>
<c>*第二行***********************</c>
<l>gen_rectangle2 (Rectangle2, Row01+Length012/2+3, Column01, 0, Length011+4, Length012/2)</l>
<l>reduce_domain (ImageBinomial011, Rectangle2, ImageReduced2)</l>
<l>threshold (ImageReduced2, Region2, 0, 120)</l>
<l>closing_rectangle1 (Region2, RegionClosing2, 2, 50)</l>
<l>closing_circle (RegionClosing2, RegionClosing21, 3.5)</l>
<l>connection (RegionClosing21, ConnectedRegions2)</l>
<l>shape_trans (ConnectedRegions2, RegionTrans2, 'rectangle1')</l>
<l>partition_rectangle (RegionTrans2, Partitioned2, 12, 32)</l>
<l>select_shape (Partitioned2, SelectedRegions2, ['area','width','height'], 'and', [100,5,20], [550,25,40])</l>
<l>intersection (SelectedRegions2, Region2, RegionIntersection2)</l>
<c>*选中字符</c>
<c>*排序</c>
<l>sort_region (RegionIntersection2, SortedRegions2, 'first_point', 'true', 'column')</l>
<c>*训练**************</c>
<l>count_obj (SortedRegions1, Number1)</l>
<l>count_obj (SortedRegions2, Number2) </l>
<c>*创建训练文件******</c>
<l>words1:=['2','0','1','6','0','7','0','7']</l>
<l>words2:=['7','2','1','2','2','0', '4']</l>
<l>TrainFile:='D:/github/CodeRecognition/QingpiWords.trf'</l>
<l>dev_set_check('~give_error') </l>
<l>delete_file(TrainFile) </l>
<l>dev_set_check('~give_error')</l>
<l>for i:=1 to Number1 by 1 </l>
<l> select_obj(SortedRegions1, SingleWord, i) </l>
<l> append_ocr_trainf(SingleWord,ImageRotate0,words1[i-1],TrainFile) </l>
<l>endfor</l>
<l>for i:=1 to Number2 by 1 </l>
<l> select_obj(SortedRegions2, SingleWord, i) </l>
<l> append_ocr_trainf(SingleWord,ImageRotate0,words2[i-1],TrainFile) </l>
<l>endfor</l>
<c>*训练ocr</c>
<l>FontFile:='D:/github/CodeRecognition/QingpiWords.omc'</l>
<l>read_ocr_trainf_names(TrainFile, CharacterNames, CharacterCount)</l>
<l>NumHidden:=400</l>
<l>*create_ocr_class_mlp (10, 20, 'constant', 'default', CharacterNames, NumHidden, 'none', 10, 42, OCRHandle)</l>
<l>read_ocr_class_mlp(FontFile, OCRHandle)</l>
<l>trainf_ocr_class_mlp (OCRHandle, TrainFile, 200, 1, 0.01, Error, ErrorLog)</l>
<l>write_ocr_class_mlp(OCRHandle, FontFile) </l>
<l>clear_ocr_class_mlp(OCRHandle)</l>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
</hdevelop>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shatanzhihu/CodeRecognition.git
git@gitee.com:shatanzhihu/CodeRecognition.git
shatanzhihu
CodeRecognition
CodeRecognition
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385