'how to display a full screen images with python2.7 and opencv2.4
I am trying to create a sort of image player with python and opencv. The images that i show are the same resolution on my screen and i would like to display them bordless in a full screen mode (without the windows bar at the bottom and the image bar at the top).
I accept also advice in order to improve my "var" used a counter for displaying the images:)
Thanks
def main():
var= 0
while True:
print 'loading images...'
if var==0:
img = cv2.imread('2-c.jpg')
var=var+1
else:
img = cv2.imread('2-d.jpg')
cv2.imshow("test",img)
key=cv2.waitKey(0)
if key==27:
break
EDIT:
I post an image and maybe i can explain myself better:
as you can see there is still the blue bar on top
Solution 1:[1]
Here is how I did it on my end:
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", img)
Solution 2:[2]
Thanks to Poko, I am gonna post the solution:
def main():
var= 0
while True:
print('loading images...')
if var==0:
img = cv2.imread('2-c.jpg')
var=var+1
else:
img = cv2.imread('2-d.jpg')
cv2.namedWindow("test", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("test", cv2.WND_PROP_FULLSCREEN, cv2.CV_WINDOW_FULLSCREEN)
cv2.imshow("test",img)
key=cv2.waitKey(0)
if key==27:
break
Solution 3:[3]
You have to create a window before doing your imshow. take a look here: http://docs.opencv.org/modules/highgui/doc/user_interface.html#namedwindow
Solution 4:[4]
I had a case where the image on the Raspberry Pi was not displayed in full screen, but only at the top in a fixed size. It helped me to add another line to the above code.
import cv2
cap = cv2.VideoCapture(0)
width, height = cap.get(3), cap.get(4)
while True:
_, frame = cap.read()
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.moveWindow("window", int((Screen_Width/2)-(width/2)), int((Screen_Height/2)-(height/2)))
cv2.imshow("window", frame)
if cv2.waitKey(1) == 27: #Esc
cap.release()
cv2.destroyAllWindows()
break
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maxime Rouiller |
| Solution 2 | Paul Jurczak |
| Solution 3 | Poko |
| Solution 4 |
