天天看點

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

拷貝到自己的項目路徑。

繼續閱讀