白色边框,同时使用python和opencv显示完整图像 [英] white border while displaying a full image with python and opencv
问题描述
这个问题与此有关: 如何显示全屏带有python2.7和opencv2.4的图像
This question is related with this one: how to display a full screen images with python2.7 and opencv2.4
我想全屏显示黑色图像,我甚至创建了具有相同屏幕分辨率的黑色图像. 但是我在屏幕的顶部和左侧都有一条白色的条纹. 我不知道这是我的屏幕不对齐还是我的代码出现问题.我尝试在2个显示器中显示白色条纹.
I want to display a black image full screen, i have created even a black image with the same resolution of the screen. But i get a little white stripe on top and on the left of the screen. I don't know if it is a problem of my screen that is not aligned or its my code. I have tried in 2 displays and the white stripe is displayed.
因此,如果您在下面运行此代码,会得到全黑图像吗?
So if you run this code below, do you get a full black image?
import numpy as np
import cv2
if __name__ == "__main__":
img = cv2.imread('nero.jpg')
cv2.namedWindow("test", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("test", cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)
cv2.imshow("test",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
这种方法对我不起作用.您是否知道另一种方式或库来显示全屏图像?
EDIT : This method is not working for me. do you know anther way or libraries to display a full screen image?
仍未解决,我开始认为这是一个openCv错误
EDIT 2: still unsolved, i am starting to think that it is an openCv bug
推荐答案
我遇到了同样的问题,在窗口的左侧和顶部都有1个像素的白色条纹.在多台显示器上进行了测试. OpenCV版本3.4.2
I have the same problem, there is a white stripe of 1 pixel on the left and on the top side of the window. Tested it with multiple monitors. OpenCV version 3.4.2
但是在我的情况下,有一种解决方法可以很好地工作(另请参见 https://gist. github.com/goraj/a2916da98806e30423d27671cfee21b6 ).这是代码:
But there is a workaround which works perfectly fine in my case (see also https://gist.github.com/goraj/a2916da98806e30423d27671cfee21b6). Here's the code:
import cv2
import win32api
import win32gui
cv2.namedWindow("fullScreen", cv2.WINDOW_FREERATIO)
cv2.setWindowProperty("fullScreen",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
hwndMain = win32gui.FindWindow(None, "fullScreen")
rgb = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 0))
GCLP_HBRBACKGROUND = -10
win32api.SetClassLong(hwndMain, GCLP_HBRBACKGROUND, rgb)
这篇关于白色边框,同时使用python和opencv显示完整图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!