Gianfra
Gianfra

Reputation: 1149

white border while displaying a full image with python and opencv

This question is related with this one: how to display a full screen images with python2.7 and opencv2.4

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?

EDIT 2: still unsolved, i am starting to think that it is an openCv bug

Upvotes: 2

Views: 3424

Answers (2)

Matt
Matt

Reputation: 83

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

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)

Upvotes: 1

Hammer
Hammer

Reputation: 10329

Yes I do.

img = np.zeros((900, 1600)) #my aspect ratio is 16x9
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)

gives me a fully black screen. Are you sure you are using the right aspect ratio?

Upvotes: 0

Related Questions