如何读取图很小,而且又不清晰的条码?

来源:互联网 发布:golang mgo 编辑:程序博客网 时间:2024/04/29 02:10

解决办法:

1、放大图片
2、通过像素直方图提取其黑色条区域

3、生成一幅新图

4、将提取黑色条区域重新生成一幅图。

5、读取条码值就可以实现。

原代码如下:

dev_close_window ()
read_image (Image, 'barcode/ean13/ean13_meas_param_estimation_09')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
zoom_image_size(Image, ImageZoom, Width*1.5, Height*1.5, 'constant')
* scale_image(Image, ImageScaled,  1, 200)


get_image_size (ImageZoom, Width, Height)
dev_open_window (0, 0, Width*1.5, Height*1.5, 'black', WindowHandle1)
dev_display (ImageZoom)


* threshold (Image, Regions, 2, 7)
threshold (ImageZoom, Regions, 95, 125)
connection(Regions, ConnectedRegions)


shape_trans(ConnectedRegions, RegionTrans,'rectangle2')
select_shape (RegionTrans, SelectedRegions, 'area', 'and', 34.05, 1000)


* select_shape (RegionTrans, SelectedRegions, 'area', 'and', 510.7, 5000)




gen_image_proto(ImageZoom, ImageCleared, 255)


paint_region(SelectedRegions, ImageCleared, ImageResult, 0, 'fill')


create_bar_code_model([], [], BarCodeHandle)
find_bar_code(ImageZoom, SymbolRegions, BarCodeHandle, 'EAN-13', DecodedDataStrings)
disp_message(WindowHandle1, DecodedDataStrings, 'window', 12, 12, 'black', 'true')
clear_bar_code_model(BarCodeHandle)




0 0
原创粉丝点击