Gianfra
Gianfra

Reputation: 1149

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: http://i39.tinypic.com/mhw1ev.jpg as you can see there is still the blue bar on top

Upvotes: 17

Views: 63192

Answers (4)

Ay_Ky
Ay_Ky

Reputation: 1

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

Upvotes: 0

Gianfra
Gianfra

Reputation: 1149

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

Upvotes: 13

Nicolas
Nicolas

Reputation: 457

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)

Upvotes: 42

Poko
Poko

Reputation: 822

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

Upvotes: 2

Related Questions