如何显示在OpenCV的全屏无边框窗口中的图像 [英] How to display an image in full screen borderless window in openCV

查看:3496
本文介绍了如何显示在OpenCV的全屏无边框窗口中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在全屏幕边框窗口来显示在OpenCV的图像。
换言之,只有图像像素将出现,没有菜单,工具栏,或窗口的背景。

使用 imshow() cvShowImage()不启用:


  1. 窗口长到全屏
    在宽度,但不高。它错过几个像素。

  2. 我不能让无国界甚至通过改变窗口的设置
    处理程序。

我认为问题的根源在于 cvNamedWindow()它创建主要方法 WS_OVERLAPPED 窗口,然后创建一个孩子,像所有的功能 imshow() cvGetWindowHandle()对孩子进行操作。

因此​​,即使Windows命令:

  SetWindowLong函数((HWND)cvGetWindowHandle(winName),GWL_STYLE,WS_VISIBLE | WS_EX_TOPMOST | WS_POPUP);

犯规的帮助,因为孩子不能成为无国界的 WS_POPUP 。有人得到了一个解决办法?


  • 也许,展示OpenCV的垫窗口
    不使用内置的方法OpenCV的

  • 或某种窗户把戏

P.S。我尝试以下code:

  cvMoveWindow(AAA,0,0);
cvSetWindowProperty(AAA,CV_WINDOW_FULLSCREEN,CV_WINDOW_FULLSCREEN);//还有我尝试这样做:
HWND HWND =(HWND)cvGetWindowHandle(AAA);
RECT windowRect;
windowRect.left = 0;
windowRect.top = 0;
windowRect.right = cxScreen; //显示分辨率
windowRect.bottom = cyScreen; //显示分辨率
AdjustWindowRect(安培; windowRect,WS_VISIBLE,FALSE);
长p_OldWindowStyle = SetWindowLongPtr(HWND,GWL_STYLE,WS_POPUP);
SetWindowPos(HWND,HWND_TOP,0,0,windowRect.right,windowRect.bottom,S​​WP_FRAMECHANGED | SWP_SHOWWINDOW);
SetWindowLong函数(HWND,GWL_STYLE,WS_VISIBLE | WS_EX_TOPMOST | WS_POPUP);


解决方案

你有没有发出 cvShowImage()来显示该窗口?因为它似乎你不这样做。无论如何,你可能要改为调用Win32 API对于这一点,所以加一个调用的ShowWindow(HWND,SW_SHOW); SetWindowPos()

如果您的当前呼叫 SetWindowPos()不会做的伎俩,检查这样的回答:<一href=\"http://stackoverflow.com/questions/5788115/hide-border-of-window-if-i-know-a-handle-of-this-window/5795633#5795633\">Hide窗口的边框,如果我知道这个窗口的句柄

我建议你没有调用 cvSetWindowProperty()起初,只是为了确保你能找到一个可行的方法。

做你的测试

刚一说明,如果你检查模块/ highgui / src目录/ window_w32.cpp 你可以看到OpenCV的是如何在Windows上创建的窗口。

修改

以下code实现我之前给了提示和绕过OP报告的问题。诀窍是不使用 cvGetWindowHandle()来检索窗口手柄,直接使用的的win32 的该API: FindWindow函数( )

 的IplImage * cv_img = cvLoadImage(test.jpg放在CV_LOAD_IMAGE_UNCHANGED);
如果(!cv_img)
{
    的printf(无法cvLoadImage \\ n);
    返回-1;
}cvNamedWindow(main_win,CV_WINDOW_AUTOSIZE);
cvMoveWindow(main_win,0,0);
cvSetWindowProperty(main_win,CV_WINDOW_FULLSCREEN,CV_WINDOW_FULLSCREEN);cvShowImage(main_win,cv_img);// HWND cv_hwnd =(HWND)cvGetWindowHandle(main_win);
//如果(!cv_hwnd)
// {
//的printf(无法cvGetWindowHandle \\ n);
//}
//输出(cvGetWindowHandle返回%P \\ N,* cv_hwnd);HWND win_handle = FindWindow函数(0,Lmain_win);
如果(!win_handle)
{
    的printf(无法FindWindow函数\\ n);
}SetWindowLong函数(win_handle,GWL_STYLE,GetWindowLong(win_handle,GWL_EXSTYLE)| WS_EX_TOPMOST);
的ShowWindow(win_handle,SW_SHOW);cvWaitKey(0);cvReleaseImage(安培; cv_img);
cvDestroyWindow(main_win);

这code将使由OpenCV的无边距创建的窗口,但你仍然可能要调整一件事或另一个是让这个操作的完美的。你会看到为什么。一种想法是调整窗口的大小,使其图像的大小。

修改

好吧,既然你说:


  

写一个演示可能会很辛苦。


我也决定要为你做这最后一部分,因为我这样一个好人=]

这是code的小的改进上面:

  HWND win_handle = FindWindow函数(0,Lmain_win);
如果(!win_handle)
{
    的printf(无法FindWindow函数\\ n);
}//调整大小
unsigned int类型标志=(SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
旗&安培; =〜SWP_NOSIZE;
unsigned int类型X = 0;
unsigned int类型Y = 0;
unsigned int类型W = cv_img-&GT;宽度;
unsigned int类型H = cv_img-&GT;高度;
SetWindowPos(win_handle,HWND_NOTOPMOST,X,Y,W,H,标志);//无边距
SetWindowLong函数(win_handle,GWL_STYLE,GetWindowLong(win_handle,GWL_EXSTYLE)| WS_EX_TOPMOST);
的ShowWindow(win_handle,SW_SHOW);

和我的系统上它会显示你问的问题是什么。

I want to display an image in OpenCV in a full screen borderless window. In other words, only the image pixels will appear, without menu, toolbar, or window background.

Using imshow() or cvShowImage() don't enable it:

  1. The window grows to be full screen in width but not in height. It misses few pixels.
  2. I could not make it borderless even by changing settings of window handler.

I think that the problem is rooted in cvNamedWindow() method which creates main WS_OVERLAPPED window, then creates a child and all functions like imshow() or cvGetWindowHandle() operate on the child.

Thus even windows command:

SetWindowLong((HWND)cvGetWindowHandle(winName), GWL_STYLE, WS_VISIBLE | WS_EX_TOPMOST | WS_POPUP);

Doesnt help, since the child cannot become borderless WS_POPUP. Someone got a workaround?

  • Maybe, showing opencv mat to window without using opencv built in methods
  • Or some kind of windows trick

P.S. I tried the following code:

cvMoveWindow("AAA",0,0);
cvSetWindowProperty("AAA", CV_WINDOW_FULLSCREEN, CV_WINDOW_FULLSCREEN);

// Also I tried this:
HWND hwnd = (HWND)cvGetWindowHandle("AAA");
RECT windowRect;
windowRect.left = 0;
windowRect.top = 0;
windowRect.right = cxScreen; //Display resolution
windowRect.bottom = cyScreen; //Display resolution
AdjustWindowRect(&windowRect,WS_VISIBLE,false);
long p_OldWindowStyle = SetWindowLongPtr(hwnd,GWL_STYLE,WS_POPUP);
SetWindowPos(hwnd,HWND_TOP,0,0,windowRect.right,windowRect.bottom,SWP_FRAMECHANGED | SWP_SHOWWINDOW);
SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE | WS_EX_TOPMOST | WS_POPUP); 

解决方案

Have you issued cvShowImage() to display the window? Because it seems you are not doing it. Anyway, you might want to call the win32 API for this instead, so add a call to ShowWindow(hwnd, SW_SHOW); after SetWindowPos().

If your current call to SetWindowPos() doesn't do the trick, check this answer: Hide border of window, if i know a handle of this window

I recommend you doing your tests without calling cvSetWindowProperty() at first, just to make sure you can find a method that works.

Just a note, if you check modules/highgui/src/window_w32.cpp you can see how OpenCV creates windows on Windows.

EDIT:

The following code implements the tips I gave before and bypasses the problems the OP reported. The trick is NOT using cvGetWindowHandle() to retrieve the windows' handle and use directly win32 API for that: FindWindow()

IplImage* cv_img = cvLoadImage("test.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!cv_img)
{
    printf("Failed cvLoadImage\n");
    return -1;
}

cvNamedWindow("main_win", CV_WINDOW_AUTOSIZE);
cvMoveWindow("main_win", 0, 0);
cvSetWindowProperty("main_win", CV_WINDOW_FULLSCREEN, CV_WINDOW_FULLSCREEN);

cvShowImage("main_win", cv_img);

//HWND cv_hwnd = (HWND)cvGetWindowHandle("main_win");
//if (!cv_hwnd)
//{
//  printf("Failed cvGetWindowHandle\n");
//}
//printf("cvGetWindowHandle returned %p\n", *cv_hwnd);

HWND win_handle = FindWindow(0, L"main_win");
if (!win_handle)
{
    printf("Failed FindWindow\n");
}

SetWindowLong(win_handle, GWL_STYLE, GetWindowLong(win_handle, GWL_EXSTYLE) | WS_EX_TOPMOST);
ShowWindow(win_handle, SW_SHOW);

cvWaitKey(0);

cvReleaseImage(&cv_img);
cvDestroyWindow("main_win");

This code will make the window created by OpenCV borderless, but you still might have to tweak one thing or another to make this operation perfect. You'll see why. One idea is to resize the window and make it the size of the image.

EDIT:

Well, since you stated:

writing a demo might be very hard

I also decided to do this last part for you, since I'm such a nice guy =]

This is a small improvement of the code above:

HWND win_handle = FindWindow(0, L"main_win");
if (!win_handle)
{
    printf("Failed FindWindow\n");
}

// Resize
unsigned int flags = (SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
flags &= ~SWP_NOSIZE;
unsigned int x = 0;
unsigned int y = 0;
unsigned int w = cv_img->width;
unsigned int h = cv_img->height;
SetWindowPos(win_handle, HWND_NOTOPMOST, x, y, w, h, flags);

// Borderless
SetWindowLong(win_handle, GWL_STYLE, GetWindowLong(win_handle, GWL_EXSTYLE) | WS_EX_TOPMOST);
ShowWindow(win_handle, SW_SHOW);

And on my system it displays exactly what you asked on the question.

这篇关于如何显示在OpenCV的全屏无边框窗口中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆