在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
《zw版·Halcon-delphi系列原创教程》 只有2行代码的超市收款单ocr脚本 发了这么多教程,有网友问,为什么没有ocr的。 下面示例的脚本,不到100行,主要是图像分割太繁琐 真正用于ocr的,就两行 92 read_ocr_class_mlp ('DotPrint', OCRHandle) 93 do_ocr_multi_class_mlp (FinalCharacters, Rotated, OCRHandle, Class, Confidence) 图1,是原图
1 * dotprt.hdev: Segmentation of a dot printing 2 * 3 dev_update_window ('off') 4 read_image (Needle, 'needle1') 5 dev_close_window () 6 get_image_size (Needle, Width, Height) 7 dev_open_window (0, 0, 2 * Width, 2 * Height, 'black', WindowID) 8 set_display_font (WindowID, 16, 'mono', 'true', 'false') 9 dev_display (Needle) 10 disp_continue_message (WindowID, 'black', 'true') 11 stop () 12 * * 13 Row1 := 50 14 Column1 := 90 15 Row2 := 250 16 Column2 := 370 17 Px := Column1 + (Column2 - Column1) / 2 18 Py := Row1 + (Row2 - Row1) / 2 19 gen_rectangle1 (Rectangle1, Row1, Column1, Row2, Column2) 20 * orientation correction 21 text_line_orientation (Needle, Needle, 35, -0.523599, 0.523599, OrientationAngle) 22 hom_mat2d_identity (HomMat2DIdentity) 23 hom_mat2d_rotate (HomMat2DIdentity, -OrientationAngle, Px, Py, HomMat2DRotate) 24 affine_trans_image (Needle, Rotated, HomMat2DRotate, 'constant', 'false') 25 dev_display (Rotated) 26 disp_continue_message (WindowID, 'black', 'true') 27 stop () 28 threshold (Rotated, RawSegmentation, 0, 105) 29 connection (RawSegmentation, ConnectedRegions) 30 select_shape (ConnectedRegions, MinSizeRegions, 'area', 'and', 6, 99999) 31 union1 (MinSizeRegions, RemovedNoise) 32 dev_display (Rotated) 33 dev_set_color ('green') 34 dev_set_draw ('fill') 35 dev_display (RemovedNoise) 36 disp_continue_message (WindowID, 'black', 'true') 37 stop () 38 clip_region (RemovedNoise, RawSegmentation, 53, 75, 260, 356) 39 dev_display (Rotated) 40 dev_display (RawSegmentation) 41 disp_continue_message (WindowID, 'black', 'true') 42 stop () 43 closing_circle (RawSegmentation, ClosedPatterns, 6) 44 opening_rectangle1 (ClosedPatterns, SplitPatterns, 1, 5) 45 connection (SplitPatterns, ConnPatterns) 46 select_shape (ConnPatterns, CharCandidates, 'area', 'and', 150, 5999) 47 shape_trans (CharCandidates, CharBlocks, 'rectangle1') 48 dev_set_draw ('margin') 49 dev_set_line_width (2) 50 dev_display (Rotated) 51 dev_display (CharBlocks) 52 disp_continue_message (WindowID, 'black', 'true') 53 stop () 54 partition_rectangle (CharBlocks, CharCandidates, 25, 100) 55 intersection (CharCandidates, RawSegmentation, Characters) 56 closing_circle (Characters, IntermedCharacters, 2.5) 57 dev_set_colored (12) 58 dev_display (Rotated) 59 dev_set_draw ('fill') 60 dev_display (IntermedCharacters) 61 disp_continue_message (WindowID, 'black', 'true') 62 stop () 63 gen_empty_obj (Characters) 64 count_obj (IntermedCharacters, NumIntermediate) 65 dev_display (Rotated) 66 for i := 1 to NumIntermediate by 1 67 dev_set_color ('red') 68 select_obj (IntermedCharacters, Char, i) 69 dev_display (Char) 70 connection (Char, CharParts) 71 select_shape (CharParts, CharCandidates, 'area', 'and', 40, 99999) 72 union1 (CharCandidates, Char) 73 dev_set_color ('green') 74 dev_display (Char) 75 * disp_continue_message (WindowID, 'black', 'true') 76 * stop () 77 concat_obj (Characters, Char, Characters) 78 endfor 79 select_shape (Characters, Heigh, 'height', 'and', 24, 50) 80 sort_region (Heigh, FinalCharacters, 'character', 'true', 'row') 81 dev_set_color ('red') 82 dev_set_draw ('margin') 83 dev_display (Rotated) 84 dev_display (FinalCharacters) 85 dev_set_color ('green') 86 dev_set_line_width (3) 87 dev_set_shape ('rectangle1') 88 dev_display (FinalCharacters) 89 dev_set_shape ('original') 90 dev_set_line_width (1) 91 dev_set_draw ('fill') 92 read_ocr_class_mlp ('DotPrint', OCRHandle) 93 do_ocr_multi_class_mlp (FinalCharacters, Rotated, OCRHandle, Class, Confidence) 94 smallest_rectangle1 (FinalCharacters, Row11, Column1, Row2, Column21) 95 count_obj (FinalCharacters, NumberFinal) 96 for i := 1 to NumberFinal by 1 97 disp_message (WindowID, Class[i - 1], 'image', Row2[i - 1], Column1[i - 1], 'green', 'false') 98 endfor 99 clear_ocr_class_mlp (OCRHandle) 100 dev_update_window ('on')
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论