halcon小程序

1.相机与机器人标定

px:=[-279,22,-306,27]
py:=[299,311,-6,-37]
pz:=[-1344,-1346,-1349,-1354]
qx:=[1158.54,1144.16,1452.72,1489.06]
qy:=[-185.5,112.86,-217.34,111.75]
qz:=[-115.79,-114.53,-114.32,-114.5]
vector_to_hom_mat3d ('rigid', px, py, pz, qx, qy, qz, HomMat3D)

affine_trans_point_3d (HomMat3D, -279, 299, -1344, Qx, Qy, Qz)

2.读取条码和QR码

create_bar_code_model ([], [], BarCodeHandle)
create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)
*read_data_code_2d_model ('C:/Users/Administrator/Desktop/2.dcm', DataCodeHandle)
*query_data_code_2d_params (DataCodeHandle, 'get_result_params', GenParamName)
set_bar_code_param (BarCodeHandle, 'element_size_min', 8)
set_bar_code_param (BarCodeHandle, 'persistence', 1)
set_bar_code_param (BarCodeHandle, 'start_stop_tolerance', 'high')
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)
* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber ('GigEVision2', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', 'GQ127000001', 0, -1, AcqHandle)
set_framegrabber_param (AcqHandle, 'TriggerMode', 'Off')
grab_image_start (AcqHandle, -1)
while (true)
    grab_image_async (Image, AcqHandle, -1)
    * Image Acquisition 01: Do something
    find_bar_code (Image, SymbolRegions1, BarCodeHandle, ['Code 128','Code 39'], BarCodeStrings)
    find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
    get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', BarCodeResults)
    get_data_code_2d_results (DataCodeHandle, DecodedDataStrings, 'status', ResultValues)
  * get_data_code_2d_param (DataCodeHandle, 'contrast_min', GenParamValue)
   * write_data_code_2d_model (DataCodeHandle, 'C:/Users/Administrator/Desktop/2.dcm')
endwhile
close_framegrabber (AcqHandle)

读取QR码可以训练模板,自动获取参数

* ***************************************************************
* This example program demonstrates how to train a 2d data model
* for a class of ECC 200 data matrix symbols and how to obtain
* the values of the model parameters before and after the training.
* Furthermore it is shown how to write the trained data code model
* into a file and how to read the saved data code model which
* is then used to find all ECC200 symbols in a sequenz of images.
* 
* Initialize image path and visual settings
dev_update_off ()
dev_close_window ()
ImageFiles := 'datacode/ecc200/ecc200_cpu_0'
ImageNum := 16
read_image (Image, ImageFiles + '07')
dev_open_window (0, 0, 760, 570, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
* 
* Display short description
* This program demonstrates the training of a 2d data code model
* and how to write the trained model into a file and also how to
* read the saved model from the file. The model is then used
* to find data codes in a sequence of images.
Message := 'This program demonstrates the training of a 2d data code'
Message[1] := 'model, how to write the trained model into a file, and'
Message[2] := 'also how to read the saved model from the file. The'
Message[3] := 'model is then used to find data codes in a sequence of'
Message[4] := 'images.'
Message[5] := 'Furthermore it is shown how to obtain the values of the'
Message[6] := 'model parameters before and after the training.'
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 ('Data Matrix ECC 200', [], [], DataCodeHandle)
* 
* Get model parameters before the training
* -------------------------------------------------------
query_data_code_2d_params (DataCodeHandle, 'get_model_params', GenParamName)
get_data_code_2d_param (DataCodeHandle, GenParamName, ModelBeforeTraining)
* 
* Step 2: Train the model
* -------------------------------------------------------
* Train the model on a dark and a bright image
* 
* Dark image
read_image (Image, 'datacode/ecc200/ecc200_cpu_007')
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, 'train', 'all', ResultHandles, DecodedDataStrings)
dev_display (Image)
dev_display (SymbolXLDs)
TitleMessage := 'Train on a dark image'
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, [], 'forest green', 'black')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Bright image
read_image (Image, 'datacode/ecc200/ecc200_cpu_008')
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, 'train', 'all', ResultHandles, DecodedDataStrings)
dev_display (Image)
dev_display (SymbolXLDs)
TitleMessage := 'Train on a bright image'
display_found_data_codes (SymbolXLDs, WindowHandle, DecodedDataStrings, TitleMessage, [], 'forest green', 'black')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Get model parameters after the training
* -------------------------------------------------------
get_data_code_2d_param (DataCodeHandle, GenParamName, ModelAfterTraining)
* 
* Display the model parameters
dev_clear_window ()
ModelAdaption := (GenParamName + ':')$'-35' + ModelBeforeTraining$'15' + ' -> ' + ModelAfterTraining
disp_message (WindowHandle, 'Model parameters before and after the training:', 'window', 12, 12, 'white', 'false')
disp_message (WindowHandle, ModelAdaption, 'window', 60, 12, 'white', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Step 3: Write the model into a file
* --------------------------------------------------------
* Save the model in a file so that it can be used later
write_data_code_2d_model (DataCodeHandle, '2d_data_code_model.dcm')
* 
* Display message about saved file and next step
dev_clear_window ()
Message := 'The data code model is saved in \'2d_data_code_model.dcm\'.'
Message[1] := ' '
Message[2] := 'In the next step the saved model is read and used to'
Message[3] := 'find data codes in a sequenz of images.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Step 4: Read an existing 2d data code model
* ----------------------------------------------------------
* Read the previously saved data code model
read_data_code_2d_model ('2d_data_code_model.dcm', DataCodeHandle)
* 
* Step 5: 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 := 7 to 16 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 - 6) + ' of ' + (ImageNum - 6)
    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

3.链接相机

* Image Acquisition 01: Code generated by Image Acquisition 01
* Image Acquisition 01: Attention: The initialization may fail in case parameters need to
* Image Acquisition 01: be set in a specific order (e.g., image resolution vs. offset).
open_framegrabber ('GigEVision2', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', '003053357e00_Basler_acA250020gm', 0, -1, AcqHandle)
set_framegrabber_param (AcqHandle, 'GainAuto', 'Continuous')
set_framegrabber_param (AcqHandle, 'GainSelector', 'All')
set_framegrabber_param (AcqHandle, 'BlackLevelSelector', 'All')
set_framegrabber_param (AcqHandle, 'Gamma', 0.929993)
set_framegrabber_param (AcqHandle, 'TestImageSelector', 'Off')
set_framegrabber_param (AcqHandle, 'AutoFunctionAOIWidth', 800)
set_framegrabber_param (AcqHandle, 'AutoFunctionAOIHeight', 600)
set_framegrabber_param (AcqHandle, 'AutoFunctionAOIOffsetX', 0)
set_framegrabber_param (AcqHandle, 'AutoFunctionAOIOffsetY', 0)
grab_image_start (AcqHandle, -1)
while (true)
    grab_image_async (Image, AcqHandle, -1)
    * Image Acquisition 01: Do something
endwhile
close_framegrabber (AcqHandle)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值