ocr_cd_print_polar_trans.hdev从cd边提取字符然后识别 相关例程学习

来源:互联网 发布:java 接口隔离原则 编辑:程序博客网 时间:2024/04/28 00:55

Index:.../Applications/OCR/ocr_cd_print_polar_trans.hdev


mean_image (Image, ImageMean, 211, 211)
dyn_threshold (Image, ImageMean, RegionDynThresh, 15, 'dark')
connection (RegionDynThresh, ConnectedRegions)
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 0)
gen_contour_region_xld (SelectedRegions, Contours, 'border')
fit_circle_contour_xld (Contours, 'ahuber', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
gen_circle (CircleO, Row, Column, Radius - 5)
gen_circle (CircleI, Row, Column, Radius - 30)
difference (CircleO, CircleI, Ring)

一开始这些提取那个边,这里面有一个我用过多次的算子,fit_circle_contour_xld ,我以前没注意过,这次看帮助文档发现,基于代数距离最小和基于几何距离最小

然后我看了一个文献,大概提到了这个,基于代数距离最小的方法算法简单,但是它将所有样本点都当作准确值,当出现噪声时,拟合误差较大,识别率下

降[4]。基于几何距离最小的方法更准确,但是它对噪声比较敏感,并未考虑所得椭圆和真实椭圆边界的拟合程度,造成较

大的偏差,甚至拟合出双曲线[8]。基于RANSAC的算法的优点是它能鲁棒地估计模型参数,但是它没有迭代次数的上限,因此,其计算复杂度具有随机性。


select_shape (ConnectedRegions1, SelectedRegions, ['area','width'], 'and', [30,4], [150,10])

这次用这个算子时,自己研究了一下特征直方图,大概明白怎么用特征直方图来选择东西了,与或关系以及合并关系,在特征直方图要选择好了。

* Rectify the region through a polar transformation
* so that the characters now are aligned along an
* horizontal line
polar_trans_image_ext (Image, ImagePolar, Row, Column, 0, rad(360), Radius - 30, Radius - 5, WidthP, HeightP, 'bilinear')
dev_open_window (0, 0, WidthP, HeightP, 'black', WindowHandle2)
rotate_image (ImagePolar, ImageRotate, 180, 'constant')

* Segment the characters
mean_image (ImageRotate, ImageMeanRotate, 51, 9)
dyn_threshold (ImageRotate, ImageMeanRotate, RegionDynThreshChar, 5, 'dark')
connection (RegionDynThreshChar, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions, ['area','width'], 'and', [30,4], [150,10])
sort_region (SelectedRegions, SortedRegions, 'character', 'false', 'column')
* Remove distractors which happen to have similar dimensions to the characters.
* From all the candidate regions pickup those consisting of dark regions
* on light background
threshold (ImageMeanRotate, Region, 90, 255)
intersection (SelectedRegions, Region, RegionIntersection)
* Filter out resulting empty regions
area_center (RegionIntersection, Area, Row1, Column1)
tuple_find (sgn(Area), 1, Indices)
select_obj (RegionIntersection, Characters, Indices + 1)

dev_display (ImageRotate)
Message := [Message,'2. Calculate polar transform']
disp_message (WindowHandle, Message, 'window', 36, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

* Read out
read_ocr_class_mlp ('Industrial_0-9A-Z', OCRHandle)
sort_region (Characters, SortedRegions, 'character', 'true', 'row')
do_ocr_multi_class_mlp (SortedRegions, ImageRotate, OCRHandle, Class, Confidence)
clear_ocr_class_mlp (OCRHandle)

字符ocr匹配这,关键选择好已有的训练模板就好。
* Correct zeros that are mistaken as capital O's.
* In a more general situation one may use a more
* complex regular expression or else the operator
* do_ocr_word_mlp()
tuple_regexp_replace (sum(Class), 'O', '0', Result)

最后还用正则表达式把O换成了0,但注意,只是把第一个O换了,具体见运行结果。

dev_set_colored (6)
dev_set_draw ('fill')
dev_display (RegionIntersection)
Message := [Message,'3. Segment and read text']
disp_message (WindowHandle, Message, 'window', 36, 12, 'black', 'true')
disp_message (WindowHandle, Result, 'image', Height / 2 - 20, Width / 2 - 150, 'black', 'true')

美观的显示结果



0 0
原创粉丝点击