*---------------------------------------------------------------------------------------------------------------------
*条码读取
*---------------------------------------------------------------------------------------------------------------------
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('C:/Users/Public/Documents/MVTec/HALCON-19.11-Progress/examples/images/barcode/code128', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
*读取图片
read_image (Image, ImageFiles[Index])
*创建一维条码模型
create_bar_code_model ([], [], BarCodeHandle1)
*查找条码
find_bar_code (Image, SymbolRegions, BarCodeHandle1, 'auto', DecodedDataStrings)
*读取条码区域
get_bar_code_object (BarCodeObjects, BarCodeHandle1, 'all', 'symbol_regions')
*获取条码信息
get_bar_code_result (BarCodeHandle1, 'all', 'decoded_strings', BarCodeResults)
*清除条码信息
clear_bar_code_model (BarCodeHandle1)
endfor
如果是要获取指定范围的方式可以采用抠图的方式 将指定位置的图片抠出 然后再识别
不如下面的图片
*读取图片
read_image (Image, 'C:/Users/宋书兵/Desktop/88_832728_1d2470c3917ee52.jpg')
rgb1_to_gray (Image, GrayImage)
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image)
*绘制ROI区域
draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
*获取指定大小区域
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*抠图改区域
reduce_domain (GrayImage, Rectangle, ImageReduced)
*创建一维条码模型
create_bar_code_model ([], [], BarCodeHandle1)
*查找条码
find_bar_code (ImageReduced, SymbolRegions, BarCodeHandle1, 'auto', DecodedDataStrings)
*读取条码区域
*get_bar_code_object (BarCodeObjects, BarCodeHandle1, 'all', 'symbol_regions')
*获取条码信息
*get_bar_code_result (BarCodeHandle1, 'all', 'decoded_strings', BarCodeResults)
*清除条码信息
clear_bar_code_model (BarCodeHandle1)