*计数器
_index:=0
*读码超时时间
_timeOut:=1000
*读码类型
_codeType:=[]
*读码数据
_codeData:=[]
*已解码的区域
gen_empty_obj (_EmptyObject)
*系统运行时间
_Runtime:=0
*系统编码格式
_coding:='utf8'
dev_close_window ()
*设置系统编码
set_system ('filename_encoding', _coding)
read_image (Image, 'C:/Users/斌/Desktop/All.png')
get_image_size(Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
rgb1_to_gray (Image, GrayImage)
_codeMode:=['Aztec Code', 'Data Matrix ECC 200', 'GS1 Aztec Code', 'GS1 DataMatrix', 'GS1 QR Code', 'Micro QR Code', 'PDF417', 'QR Code']
*创建二维码数据class模型
count_seconds (T1)
for i := 0 to |_codeMode|-1 by 1
create_data_code_2d_model (_codeMode[i],[], [],DataCodeHandle)
*设置超时时间
set_data_code_2d_param (DataCodeHandle, 'timeout', _timeOut)
*防止误识别设置,因为某些二维码模型没有这个属性,会报错所以try以下
try
set_data_code_2d_param (DataCodeHandle, 'strict_quiet_zone', 'yes')
catch (Exception)
continue
endtry
*开始识别
find_data_code_2d (GrayImage,SymbolXLDs,DataCodeHandle, 'stop_after_result_num',1000,ResultHandles, DecodedDataStrings)
dev_display (SymbolXLDs)
count_obj (SymbolXLDs, Number)
if (Number)
*存读码类型
for j := 1 to Number by 1
*存解码类型
_codeType[_index]:=_codeMode[i]
*存解码数据
_codeData[_index]:=DecodedDataStrings[j-1]
_index:=_index+1
select_obj (SymbolXLDs, ObjectSelected, j)
*存二维码区域
concat_obj (_EmptyObject, ObjectSelected, _EmptyObject)
endfor
endif
*清除识别缓存
clear_data_code_2d_model(DataCodeHandle)
endfor
count_seconds (T2)
_Runtime:=T2-T1
dev_clear_window ()
dev_display (Image)
dev_set_color ('green')
set_display_font (WindowHandle, 30, 'mono', 'true', 'false')
write_string (3600, '总耗时:'+_Runtime)
for Index := 0 to |_codeData|-1 by 1
select_obj (_EmptyObject, ObjectSelected, Index+1)
dev_display (ObjectSelected)
area_center_xld (ObjectSelected, Area, Row, Column, PointOrder)
disp_message (3600, ['类型:'+_codeType[Index],'数据:'+_codeData[Index]], 'window', Row,Column-200, 'green', 'false')
endfor
测试附图:
图一:
图二: