Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to display an image with OpenCV as a Screen Saver on Windows

I am trying to create a screen saver with OpenCV and the scrnsave library on Windows. To start I have tried to display an image using the cv::imshow function. To do this I load the image from my computer with the cv::imread function, after that I instantiate a window with the name "image" and then get the handler of that window, and set the parent to the handler provided by the scrnsave library.

However, using the code below it will give me an gray window with nothing on it, it shouldn't be decorated with maximum, minimize or exit buttons. I want the actual image to be drawn to the foreground on top of everything with the handler provided by the Windows library, just like drawing a red circle onto a black background.

I didn't find anything on the web explaining how to implement OpenCV routines into my screen saver. imshow, and set the parent of the window to the HWND handler provided by the scrnsave library.

Here is my abbreviated code for my screen saver:

LRESULT WINAPI ScreenSaverProc(HWND hWnd, 
     UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CREATE:{
             myImage = cv::imread("path/to/my/folder/image.png", CV_LOAD_IMAGE_UNCHANGED);
             cv::namedWindow("image",cv::WINDOW_AUTOSIZE);
             cv::imshow("image",myImage);
             HWND hWnd2 = (HWND) cvGetWindowHandle("image"); 
             ::SetParent(hWnd2, hWnd);
             ::ShowWindow(hWnd, SW_HIDE);
            return 0;
        }
        case WM_DESTROY:{
            cv::destroyWindow("image");
            PostQuitMessage(0);
            return 0;
        }
    }
    return DefScreenSaverProc(hWnd,message,wParam,lParam);
}

Once again it just gave me a empty and gray window, it seems to have created a separate window instead of drawing it onto the foreground.

How to display an image with OpenCV as a Screen Saver on Windows

I am trying to create a screen saver with OpenCV and the scrnsave library on Windows. To start I have tried to display an image using the cv::imshow function. To do this I load the image from my computer with the cv::imread function, after that I instantiate a window with the name "image" and then get the handler of that window, and set the parent to the handler provided by the scrnsave library.

However, using the code below it will give me an gray window with nothing on it, it shouldn't be decorated with maximum, minimize or exit buttons. I want the actual image to be drawn to the foreground on top of everything with the handler provided by the Windows library, just like drawing a red circle onto a black background.

I didn't find anything on the web explaining how to implement OpenCV routines into my screen saver. imshow, and set the parent of the window to the HWND handler provided by the scrnsave library.

Here is my abbreviated code for my screen saver:

LRESULT WINAPI ScreenSaverProc(HWND hWnd, 
     UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CREATE:{
             myImage = cv::imread("path/to/my/folder/image.png", CV_LOAD_IMAGE_UNCHANGED);
             cv::namedWindow("image",cv::WINDOW_AUTOSIZE);
             cv::imshow("image",myImage);
             HWND hWnd2 = (HWND) cvGetWindowHandle("image"); 
             ::SetParent(hWnd2, hWnd);
             ::ShowWindow(hWnd, SW_HIDE);
            return 0;
        }
        case WM_DESTROY:{
            cv::destroyWindow("image");
            PostQuitMessage(0);
            return 0;
        }
    }
    return DefScreenSaverProc(hWnd,message,wParam,lParam);
}

Once again it just gave me a empty and gray window, it seems to have created a separate window instead of drawing it onto the foreground.

How to display an image with OpenCV as a Screen Saver on Windows

I am trying to create a screen saver with OpenCV and the scrnsave library on Windows. To start I have tried to display an image using the cv::imshow function. To do this I load the image from my computer with the cv::imread function, after that I instantiate a window with the name "image" and then get the handler of that window, and set the parent to the handler provided by the scrnsave library.

However, using the code below it will give me an gray window with nothing on it, it shouldn't be decorated with maximum, minimize or exit buttons. I want the actual image to be drawn to the foreground on top of everything with the handler provided by the Windows library, just like drawing a red circle onto a black background.

I didn't find anything on the web explaining how to implement OpenCV routines into my screen saver. imshow, and set the parent of the window to the HWND handler provided by the scrnsave library.saver.

Here is my abbreviated code for my screen saver:

LRESULT WINAPI ScreenSaverProc(HWND hWnd, 
     UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CREATE:{
             myImage = cv::imread("path/to/my/folder/image.png", CV_LOAD_IMAGE_UNCHANGED);
             cv::namedWindow("image",cv::WINDOW_AUTOSIZE);
             cv::imshow("image",myImage);
             HWND hWnd2 = (HWND) cvGetWindowHandle("image"); 
             ::SetParent(hWnd2, hWnd);
             ::ShowWindow(hWnd, SW_HIDE);
            return 0;
        }
        case WM_DESTROY:{
            cv::destroyWindow("image");
            PostQuitMessage(0);
            return 0;
        }
    }
    return DefScreenSaverProc(hWnd,message,wParam,lParam);
}

Once again it just gave me a empty and gray window, it seems to have created a separate window instead of drawing it onto the foreground.

How to display an image with OpenCV as a Screen Saver on Windows

I am trying to create a screen saver with OpenCV and the scrnsave library on Windows. To start I have tried to display an image using the cv::imshow function. To do this I load the image from my computer with the cv::imread function, after that I instantiate a window with the name "image" and then get the handler of that window, and set the parent to the handler provided by the scrnsave library.

However, using the code below it will give me an gray window with nothing on it, it shouldn't be decorated with maximum, minimize or exit buttons. I want the actual image to be drawn to the foreground on top of everything with the handler provided by the Windows library, just like drawing a red circle onto a black background.

I didn't find anything on the web explaining how to implement OpenCV routines into my screen saver.

Here is my abbreviated code for my screen saver:

LRESULT WINAPI ScreenSaverProc(HWND hWnd, 
     UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CREATE:{
             myImage = cv::imread("path/to/my/folder/image.png", CV_LOAD_IMAGE_UNCHANGED);
             cv::namedWindow("image",cv::WINDOW_AUTOSIZE);
             cv::imshow("image",myImage);
             HWND hWnd2 = (HWND) cvGetWindowHandle("image"); 
             ::SetParent(hWnd2, hWnd);
             ::ShowWindow(hWnd, SW_HIDE);
            return 0;
        }
        case WM_DESTROY:{
            cv::destroyWindow("image");
            PostQuitMessage(0);
            return 0;
        }
    }
    return DefScreenSaverProc(hWnd,message,wParam,lParam);
}

Once again it just gave me a empty and gray window, it seems to have created a separate window instead of drawing it onto the foreground.