halcon读取二维码的时候显示的读取结果一直闪烁

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nineleafclover/article/details/78165616
dev_update_off ()
*关闭更新
SequenceName := '1/1.jpg'
open_framegrabber ('DirectShow', 0, 0, 0, 0, -1, 0, 'progressive', -1, 'default', -1, 'false', 'default', 'Integrated Webcam', 0, -1, FGHandle)
*打开图像获取设备并配置  返回FGHandle
grab_image (Image, FGHandle)
*从指定的图像获取设备中同步获取图像 给Image
* grab_image_async (Image, FGHandle, -1)
*从指定的图像获取设备中异步获取图像 
get_image_size (Image, Width, Height)
*获取Image的宽跟高
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
*打开窗口并将图像填充进去 填充位置为 0 0 到width height 返回 WindowHandle
set_display_font (WindowHandle, 14, 'courier', 'true', 'false')
* 设置字体       

* create_bar_code_model([],[],BarCodeHandle)
create_data_code_2d_model ('QR Code', 'default_parameters', 'maximum_recognition', QRCodeHandle)

* create_data_code_2d_model ('Data Matrix ECC 200', [], [], DMCodeHandle)

* 建立二维码模型       码类型   需要调整的项目  调整的值  返回句柄
set_data_code_2d_param (QRCodeHandle, 'default_parameters', 'maximum_recognition')
*设置二维码模型的参数
*  set_data_code_2d_param (DataCodeHandle, 'default_parameters', 'standard_recognition')
while (1)
    grab_image (Image, FGHandle)
* 从设备中获取图像






dev_display(Image)





*图像更新关闭 
    dev_update_var ('off')
    count_seconds (T1)
    *获取时间点
*     find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings3)
    find_data_code_2d (Image, SymbolXLDs1, QRCodeHandle, 'stop_after_result_num', 2, ResultHandles1, DecodedDataStrings1)
*     find_data_code_2d (Image , SymbolXLDs2, DMCodeHandle, [], [], ResultHandles2, DecodedDataStrings2)


    *查找并读取二维码的内容 输入图像 输出的轮廓  二维码模型的处理 处理的参数 处理的数据 成功读取二维码的符号  检测结果
    count_seconds (T2)
    *获取时间点
    dev_update_var ('on')
    *图像更新打开
    *
    * display the runtime and the found symbols

    set_system('filename_encoding','utf8')
    set_system ('flush_graphic', 'false')
 *设置halcon的系统参数   刷新图像  false   
    dev_display (Image)
    *显示图像
 disp_message (WindowHandle, 'Time = ' + (1000 * (T2 - T1))$'.1f' + 'ms', 'image', 1, 1, 'magenta', 'false')
 *写一条文本  左上角显示用时 

    dev_set_color ('green')
 *设置颜色
    dev_display (SymbolXLDs1)
 *显示二维码轮廓

    for i := 0 to |ResultHandles1| - 1 by 1
 *从零到检测到的二维码减一个循环 每次加一       
        select_obj (SymbolXLDs1, SymbolXLD1, i + 1)
 *获取object tuple中某个值 输入  输出  index
        get_contour_xld (SymbolXLD1, Row, Col)
 *返回轮廓的坐标  输入轮廓 返回轮廓的行  列
        get_string_extents (WindowHandle, DecodedDataStrings1[i], Ascent, Descent, TxtWidth, TxtHeight)
 *获取文字的空间的大小     文字 最大高度 最大扩展 宽度 高度
        TxtCol := min(Col)
        if (TxtCol + TxtWidth > Width)
            disp_message (WindowHandle, DecodedDataStrings1[i], 'image', max(Row), max([min(Col) - TxtWidth,1]), 'green', 'false')
        else
            disp_message (WindowHandle, DecodedDataStrings1[i], 'image', max(Row), min(Col), 'green', 'false')
        endif
 *防止文字超出
    endfor
    set_system ('flush_graphic', 'true')
    disp_line (WindowHandle, -101, -101, -99, -99)
*     disp_continue_message (WindowHandle, 'black', 'true')
*     stop ()
endwhile
close_framegrabber (FGHandle)
clear_data_code_2d_model (DataCodeHandle)

今天在学习用halcon二维码的时候发现读出来的数据一直闪烁,在对比之前的程序发现,中间有一行添加了一句话
dev_display(Image)
这句话导致窗口中显示了未处理的图片,造成显示的数据闪烁。

猜你喜欢

转载自blog.csdn.net/nineleafclover/article/details/78165616
今日推荐