批号、日期等任何行业的各种字符信息都会作为检测项目在生产线上通过图像处理检测装置加以识别。
1.OCR识别的一般流程
2.OCR的各种定位方法
* Segment the outer circle
mean_image (Image, ImageMean, 51, 51)
dyn_threshold (Image, ImageMean, RegionDynThresh, 15, 'dark')
fill_up (RegionDynThresh, RegionFillUp)
gen_contour_region_xld (RegionFillUp, ContourBorder, 'border')
fit_circle_contour_xld (ContourBorder, 'ahuber', -1, 0, 0, 3, 2, CenterRow, CenterColumn, Radius, StartPhi, EndPhi, PointOrder)
dev_display (Image)
dev_set_color ('green')
dev_display (ContourBorder)
write_message (WindowHandle, -1, -1, 'Segmented circle', true)
stop ()
*
* Transform the annulus with the characters to polar coordinates
WidthPolar := 2*Pi*Radius*AnnulusOuter
HeightPolar := Radius*(AnnulusOuter-AnnulusInner)
RadiusStart := Radius*AnnulusOuter
RadiusEnd := Radius*AnnulusInner
AngleStart := 2*Pi - 2*Pi/WidthPolar
AngleEnd := 0
polar_trans_image_ext (Image, PolarTransImage, CenterRow, CenterColumn, AngleStart, AngleEnd, RadiusStart, RadiusEnd, WidthPolar, HeightPolar, 'bilinear')
reopen_window_fit (PolarTransImage, 1000, 0, 0, WindowHandle)
dev_display (PolarTransImage)
stop ()
*
* Segment the characters
CharWidth := WidthPolar * CharWidthFraction
CharHeight := CharWidth
mean_image (PolarTransImage, ImageMean, 2*CharWidth, 2*CharHeight)
dyn_threshold (PolarTransImage, ImageMean, RegionThreshold, 10, 'dark')
connection (RegionThreshold, ConnectedRegions)
select_shape (ConnectedRegions, RegionChar, ['height','width','row'], 'and', [CharHeight*0.1, CharWidth*0.3, HeightPolar*0.25], [CharHeight*1.1, CharWidth*1.1, HeightPolar*0.75])
sort_region (RegionChar, RegionCharSort, 'character', 'true', 'row')
dev_set_colored (12)
dev_display (PolarTransImage)
dev_display (RegionCharSort)
stop ()
invert_image (Image, ImageInvert) bin_threshold (ImageInvert, RawSegmentation) fill_up_shape (RawSegmentation, RemovedNoise, 'area', 1, 5) opening_circle (RemovedNoise, ThickStructures, 2.5) dev_display (Image) dev_set_color ('green') dev_display (ThickStructures) disp_continue_message (WindowID, 'black', 'true') stop () dev_set_draw ('margin') dev_set_line_width (3) dev_display (Image) dev_display (ThickStructures) disp_continue_message (WindowID, 'black', 'true') stop () closing_circle (ThickStructures, RegionClosing, 3.5) dev_display (Image) dev_display (RegionClosing) disp_continue_message (WindowID, 'black', 'true') stop () connection (RegionClosing, ConnectedRegions) intersection (ConnectedRegions, ConnectedRegions, NumberCandidates) dev_set_colored (12) dev_display (Image) dev_display (NumberCandidates) disp_continue_message (WindowID, 'black', 'true') stop () select_shape (NumberCandidates, Numbers, 'area', 'and', 300, 9999) sort_region (Numbers, FinalNumbers, 'first_point', 'true', 'column')
* 获取喷码区域
* Enhance circular dots in an image
dots_image (GrayImage, DotImage, 5, 'dark', 2)
threshold(DotImage, Region, 30,255)
* 形态学运算操作,将单体字符连在一起
closing_rectangle1 (Region, RegionClosing, 1, 7)
closing_rectangle1 (RegionClosing, RegionClosing1, 7, 1)
gen_rectangle2 (Rectangle, 10, 10, rad(45), 3, 0)
closing (RegionClosing1, Rectangle, RegionClosing2)
gen_rectangle2 (Rectangle, 10, 10, rad(135), 3, 0)
closing (RegionClosing2, Rectangle, RegionClosing3)
connection (RegionClosing3, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','height'], 'and', [100,50], [1000,70])
* 排序为下步识别做准备
sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'row')
area_center (SortedRegions, Area, Row, Column)
3.相关算子
参考文献:
1.826工作室小马_xiao halcon实战讲解系列5之ocr1 ocr识别的一般流程
代码链接:
10/8/2015 3:30:26 PM