(转)halcon识别奶茶包装上的激光打码日期
By
admin
at 2018-03-01 • 0人收藏 • 1858人看过
识别之后:
dev_update_off() read_image (Image, 'C:/Users/Administrator/Desktop/4_23279_6abb05588c14409.bmp') dev_close_window() get_image_size(Image, Width, Height) dev_open_window_fit_image(Image, 0, 0, -1, -1, WindowHandle) set_display_font(WindowHandle, 16, 'mono', 'true', 'false') dev_display(Image) disp_continue_message(WindowHandle, 'black', 'true') stop() Row1 := 300 Col1 := 130 Row2 := 410 Col2 := 450 Px := Col1 + (Col2-Col1)/2 Py := Row1 + (Row2-Row1)/2 gen_rectangle1(Rectangle,Row1,Col1,Row2,Col2) text_line_orientation(Rectangle, Image, 25, -0.523599, 0.523599, OrientationAngle) hom_mat2d_identity(HomMat2DIdentity) hom_mat2d_rotate(HomMat2DIdentity, -OrientationAngle, Px, Py, HomMat2DRotate) affine_trans_image(Image, ImageAffinTrans, HomMat2DRotate, 'constant', 'false') dev_display(ImageAffinTrans) disp_continue_message(WindowHandle, 'black', 'true') stop() emphasize(ImageAffinTrans,ImageEmphasize,30,7,2) threshold (ImageEmphasize, Regions, 0, 84) connection(Regions, ConnectedRegions) * select_shape (ConnectedRegions, SelectedRegions, 'row', 'and', 331.19, 399.08) union1(ConnectedRegions, RegionUnion) dev_display(ImageAffinTrans) dev_set_color('green') dev_set_draw('fill') dev_display(RegionUnion) disp_continue_message(WindowHandle, 'black', 'true') stop() clip_region(RegionUnion, RegionClipped, 320, 127, 400, 470) dev_display(ImageAffinTrans) dev_display(RegionClipped) disp_continue_message(WindowHandle, 'black', 'true') stop() closing_circle(RegionClipped, RegionClosing, 5.5) connection(RegionClosing, ConnectedRegions1) shape_trans(ConnectedRegions1, RegionTrans, 'rectangle2') dev_set_line_width(2) dev_set_draw('margin') dev_display(ImageAffinTrans) dev_display(RegionTrans) disp_continue_message(WindowHandle, 'black', 'true') stop() partition_rectangle(RegionTrans, Partitioned, 25, 35) intersection(Partitioned, RegionClipped, RegionIntersection) closing_circle(RegionIntersection, RegionClosing1, 2.5) dev_set_colored(12) dev_set_draw('fill') dev_display(ImageAffinTrans) dev_display(RegionClosing1) disp_continue_message(WindowHandle, 'black', 'true') stop() gen_empty_obj (ObjectsConcat) count_obj (RegionClosing1, Number) sort_region (RegionClosing1, SortedRegions, 'first_point', 'true', 'column') dev_display (ImageAffinTrans) for Index := 1 to Number by 1 dev_set_color ('red') select_obj (SortedRegions, ObjectSelected, Index) dilation_circle (ObjectSelected, RegionDilation, 3.5) erosion_circle (RegionDilation, RegionErosion, 2.5) dev_display (RegionErosion) connection (RegionErosion, ConnectedRegions2) select_shape (ConnectedRegions2, SelectedRegions, 'area', 'and', 180, 385.229) union1 (SelectedRegions, RegionUnion1) dev_set_color ('green') dev_display (RegionUnion1) concat_obj (ObjectsConcat, RegionUnion1, ObjectsConcat) endfor read_ocr_class_mlp ('C:/Program Files/MVTec/HALCON-13.0/ocr/DotPrint_0-9A-Z_NoRej.omc', OCRHandle) do_ocr_multi_class_mlp (ObjectsConcat, ImageAffinTrans, OCRHandle, Class, Confidence) smallest_rectangle1 (ObjectsConcat, Row11, Column1, Row21, Column2) count_obj (ObjectsConcat, Number1) for Index1 := 1 to Number1-1 by 1 disp_message (WindowHandle, Class[Index1], 'window', Row11[Index1], Column1[Index1]-20, 'green', 'true') endfor
本文转自:http://www.ihalcon.com/read-9302.html
登录后方可回帖