学习记录留以备忘
下面是生成QR码的一个网站:
在线生成 QR Code (oschina.net)https://tool.oschina.net/qr
下面是用python生成QR码的一个实现,具体直接看吧:
python之qrcode模块生成二维码 - 简书 (jianshu.com)https://www.jianshu.com/p/c0073c6aa544
下面这是一个JavaScript生成QR码的国外的一个程序:
How to Create a QR Code (davidwalsh.name)https://davidwalsh.name/create-qr-codeGitHub - soldair/node-qrcode: qr code generatorhttps://github.com/soldair/node-qrcode
下面是HALCON解码的步骤介绍:
Halcon的一维条码解码步骤和解码技巧 - xh6300 - 博客园 (cnblogs.com)https://www.cnblogs.com/xh6300/p/10484995.html
下面是HALCON自带的示例,思路就大差不差
* ***********************************************************
* This example program demonstrates how to read QR codes with
* manually adapted parameter settings to optimize the
* recognition and runtime.
*
* The following parameters are set manually:
* - 'version'
* - 'model_type'
* - 'module_size_min'
* - 'module_size_max'
* - 'module_gap'
* - 'mirrored'
* - 'contrast_min'
*
* ************************************************************
*
* Initialize image path and visual settings
dev_update_off ()
dev_close_window ()
ImageFiles := 'datacode/qrcode/qr_workpiece_'
ImageNum := 9
read_image (Image, ImageFiles + '07')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
*
* Display short description
Message := 'This program demonstrates how to read QR data codes'
Message[1] := 'with manually adapted parameter settings.'
Message[2] := ' '
Message[3] := 'The following parameters are adapted to optimize the'
Message[4] := 'recognition and runtime:'
Message[5] := ' '
Message[6] := ' - \'version\''
Message[7] := ' - \'model_type\''
Message[8] := ' - \'module_size_min\''
Message[9] := ' - \'module_size_max\''
Message[10] := ''
Message[11] := ' - \'module_gap\''
Message[12] := ' - \'mirrored\''
Message[13] := ' - \'contrast_min\''
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Step 1: Create a 2d data code model
* ----------------------------------------------------
* Create a 2d data code model of the 2d data code class
* 'Data Matrix ECC 200'. The operator returns a handle to
* the 2d data code model which can be used for all further
* operations on the data code.
create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)
*
* Step 2: Adapt some parameters manually
* ----------------------------------------------------
* Set some selected parameters of the 2d data code model
* in order to adapt the model to the symbol appearance.
set_data_code_2d_param (DataCodeHandle, 'version', 1)
set_data_code_2d_param (DataCodeHandle, 'model_type', 2)
set_data_code_2d_param (DataCodeHandle, ['module_size_min','module_size_max'], [5,6])
set_data_code_2d_param (DataCodeHandle, 'module_gap', 'no')
set_data_code_2d_param (DataCodeHandle, 'mirrored', 'no')
set_data_code_2d_param (DataCodeHandle, 'contrast_min', 10)
*
* Step 3: Read the data codes
* ----------------------------------------------------
* Search and read the data codes in each image and
* display the decoded string for each found data code
for Index := 1 to ImageNum by 1
read_image (Image, ImageFiles + Index$'.2d')
dev_display (Image)
*
* Find and decode the data codes and measure the runtime
count_seconds (T1)
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
count_seconds (T2)
Time := 1000 * (T2 - T1)
*
* Display the results
TitleMessage := 'Image ' + Index + ' of ' + ImageNum
ResultMessage := 'Data code found in ' + Time$'.1f' + ' ms'
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, ResultMessage, 'forest green', 'black')
*
* Deactivate the following lines to run the program without breaks
if (Index < ImageNum)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
*
* Clear the 2d data code model
clear_data_code_2d_model (DataCodeHandle)
下面这个是做的多二维码识别:
halcon二维码识别(多类型解码+多数量解码) - 算法网 (itpcb.com)https://itpcb.com/a/713497因为每次看代码都要验证一下,这里备忘一下代码:
封装的代码:
*输入参数:
*coding:='utf8' 编码
*path:=图片路径
*timeOut:=超时时间
*count:=检测数量
*输出参数:
*EmptyObject XLD轮廓
*Runtime 耗时
*type_and_data 类型与数据
type_and_data:=[]
num:=0
gen_empty_obj (EmptyObject)
set_system ('filename_encoding', coding)
read_image (Image, path)
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],'default_parameters', 'maximum_recognition',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', count,ResultHandles, DecodedDataStrings)
dev_display (SymbolXLDs)
count_obj (SymbolXLDs, Number)
if (Number)
*存类型
type_and_data[num]:=_codeMode[i]
num:=num+1
for j := 1 to Number by 1
*存数据
type_and_data[num]:=DecodedDataStrings[j-1]
num:=num+1
select_obj (SymbolXLDs, ObjectSelected, j)
*保存XLD轮廓
concat_obj (EmptyObject, ObjectSelected, EmptyObject)
endfor
endif
*清除识别缓存
clear_data_code_2d_model(DataCodeHandle)
endfor
count_seconds (T2)
Runtime:=T2-T1
return ()
调用的代码:
*输入参数:
*coding:='utf8' 编码
*path:= 图片路径
*timeOut:=超时时间
*count:=检测数量
*输出参数:
*EmptyObject XLD轮廓
*Runtime 耗时
*type_and_data 类型与数据
find_code_discern (EmptyObject1,'utf8' ,'C:/Users/斌/Desktop/微信图片_20190815160409.jpg',500 ,10 , type_and_data1, Runtime1)
最后是一个OPENCV做的二维码定位