本帖最后由 halcon2016 于 2024-4-3 11:08 编辑
你提供的jpg图片在halcon中打不开,我把它转换成了bmp格式
- create_data_code_2d_model ('QR Code', 'default_parameters', 'maximum_recognition', DataCodeHandle)
- dev_get_window (WindowHandle)
- set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
- for Index := 1 to 4 by 1
- read_image (Image, Index+'.bmp')
- threshold (Image, Region, 250, 255)
- fill_up (Region, RegionFillUp)
- connection (RegionFillUp, ConnectedRegions)
- select_shape (ConnectedRegions, SelectedRegions, ['area','rectangularity'], 'and', [60000,0.8], [70000,1])
- shape_trans (SelectedRegions, RegionTrans, 'rectangle2')
- area_center (RegionTrans, Area, Row, Column)
- gen_cross_contour_xld (Cross, Row, Column, 26, 0.785398)
-
- reduce_domain (Image, RegionTrans, ImageReduced)
- smooth_image (ImageReduced, ImageSmooth, 'gauss', 0.5)
- find_data_code_2d (ImageSmooth, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
-
- *提取二维码准确区域
- erosion_rectangle1 (RegionTrans, RegionErosion, 11, 11)
- reduce_domain (Image, RegionErosion, ImageReduced1)
- threshold (ImageReduced1, Region1, 0, 200)
- shape_trans (Region1, RegionTrans1, 'rectangle2')
- area_center (RegionTrans1, Area1, Row2, Column2)
- gen_cross_contour_xld (Cross2, Row2, Column2, 26, 0)
-
- *也可直接用SymbolXLDs求二维码区域中心
- * area_center_xld (SymbolXLDs, Area1, Row1, Column1, PointOrder)
- * gen_cross_contour_xld (Cross1, Row1, Column1, 26, 0)
-
- dev_display (Image)
- get_draw (WindowHandle, Mode)
- dev_set_draw ('margin')
- dev_set_color ('red')
- dev_display (RegionTrans)
- dev_display (Cross)
- dev_set_color ('green')
- dev_display (RegionTrans1)
- dev_disp_text (DecodedDataStrings, 'image', Row2+10, Column2+10, 'green', [], [])
- dev_display (Cross2)
- dev_set_draw (Mode)
- stop ()
- endfor
复制代码
|