标签:play 释放 图像 lis ack decode 清除 成功 users
**********************初阶,创建-识别-清除***************************create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)
read_image(Image1,'C:/Users/研发/Pictures/Saved Pictures/二维码/123456.PNG')
find_data_code_2d(Image1, SymbolXLDs1, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
clear_data_code_2d_model (DataCodeHandle)
***********************进阶,创建-训练-识别-清除**********************
*训练二维码,只需将find_data_code_2d_model中的参数设为train、all
Path:='D:\\IPI\\Halcon12Projects\\二维码训练模板.dcm'
*创建
create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)
list_files ('D:/2dcode', 'files', Files)
for Index:=0 to |Files|-1 by 1
read_image (Image, Files[Index])
*训练
find_data_code_2d (Image,SymbolXLDs,DataCodeHandle,'train','all', ResultHandles, DecodedDataStrings)
endfor
*写入本地
write_data_code_2d_model(DataCodeHandle,Path)
*使用训练的模板进行识别,若识别失败,则进行训练当前图像(若训练后识别成功,则将训练后的句柄写入)
file_exists(Path, FileExists)
if(FileExists=1)
*读取本地
read_data_code_2d_model (Path, DataCodeHandle)
list_files ('D:/2dcode', 'files', Files)
for Index:=0 to |Files|-1 by 1
read_image (Image, Files[Index])
*使用训练的句柄识别
find_data_code_2d(Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
count_obj(SymbolXLDs, Number)
*判断围绕二维码的轮廓是否小于1
if(Number<1)
find_data_code_2d (Image,SymbolXLDs,DataCodeHandle,'train','all', ResultHandles, DecodedDataStrings)
count_obj(SymbolXLDs,Number)
if(Number>0)
write_data_code_2d_model (DataCodeHandle,Path)
endif
endif
if(Number<1)
disp_message(3600,'NG', 'window', 12, 12, 'black', 'true')
else
disp_message(3600,'OK\r\n'+DecodedDataStrings, 'window', 12, 12, 'black', 'true')
dev_display (SymbolXLDs)
endif
endfor
write_data_code_2d_model (DataCodeHandle,Path)
else
stop()
endif
*清除句柄,释放内存
clear_data_code_2d_model (DataCodeHandle)
标签:play 释放 图像 lis ack decode 清除 成功 users
原文地址:http://blog.51cto.com/green906/2157684