天天看点

HALCON error #5190: Invalid window parameter的解决办法(需要hcanvas.dll文件)

Halcon对窗口的操作有两类:

1、dev_open_window 打开实体的窗体,显示图像

2、open_window 打开虚拟的窗体,实际是图像放入缓存

*参见官方例程advanced_visualization_settings.hdev
dev_close_window()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_window_param (WindowHandle, 'graphics_stack', 'true') //default value: 'false'
set_window_param(WindowHandle, 'flush', 'false') //default value: 'true'
dev_clear_window()
read_image (Image, 'printer_chip/printer_chip_01')
dev_display(Image)
disp_message(WindowHandle, '0', 'window', 12, 12, 'black', 'true')
set_window_param(WindowHandle, 'flush', 'true')
disp_cross(WindowHandle, 32, 32, 6, 0)
stop()
*参见官方例程projective_trans_image.hdev
*参见官方文档C:/Program Files/MVTec/HALCON-19.11-Progress/doc/html/reference/operators/HWindow.html
*a buffer window to create
open_window (0, 0, 256, 256, 0, 'buffer', '', WindowHandleBuffer)//注意参数是'buffer'
get_window_param (WindowHandleBuffer, 'graphics_stack', Value1)
get_window_param (WindowHandleBuffer, 'flush', Value2)
set_window_param (WindowHandleBuffer, 'graphics_stack', 'true') //default value: 'false'
set_window_param (WindowHandleBuffer, 'flush', 'true') //default value: 'true'
get_window_param (WindowHandleBuffer, 'graphics_stack', Value1)
get_window_param (WindowHandleBuffer, 'flush', Value2)
*flush_buffer (WindowHandleBuffer)
clear_window (WindowHandleBuffer)
read_image (Image, 'printer_chip/printer_chip_01')
get_image_size (Image, Width, Height)
disp_obj (Image, WindowHandleBuffer)
* Display contour of a rectangle
Row1:=10
Column1:=10
Row2:=100
Column2:=100
set_color (WindowHandleBuffer, 'red')
disp_line(WindowHandleBuffer,Row1,Column1,Row1,Column2)
disp_line(WindowHandleBuffer,Row1,Column2,Row2,Column2)
disp_line(WindowHandleBuffer,Row2,Column2,Row2,Column1)
disp_line(WindowHandleBuffer,Row2,Column1,Row1,Column1)
dev_close_window()
dev_open_window (0, 0, 256, 256, 'black', WindowHandle)
*Display the image in the buffer window and copy it to the visible window.
copy_rectangle (WindowHandleBuffer, WindowHandle, 0, 0, Height - 1, Width - 1, 0, 0)
close_window (WindowHandleBuffer)
stop()
我在Visual C++项目中,遇到了这个问题,SetWindowParam函数执行时,总是报异常:
HALCON error #5190: Invalid window parameter
QScopedPointer<HalconCpp::HWindow> halconBuffer;
try {
        // initialize HALCON buffer window
        halconBuffer.reset(new HWindow(0, 0,  256, 256, 0, "buffer", ""));
        // turn on graphics stack, so image and regions stay even after zooming or
        // resizing
        halconBuffer->SetWindowParam("graphics_stack", "true");
        // turn on explicit flushing
        halconBuffer->SetWindowParam("flush", "false");
        // register update callback
        halconBuffer->SetContentUpdateCallback((void *) &ContentUpdateCallback, this);
    } catch (HException &except) {
        qDebug(except.ErrorMessage().Text());
}      

解决办法如下:

SetWindowParam函数需要依赖动态库文件hcanvas.dll,把该库从

C:\Program Files\MVTec\HALCON-xxx\bin\x64-win64

拷贝到自己的项目路径。

继续阅读