0

I'm using python 3.7.6 and openCV. I want to display large size images(8K bmp) frame by frame, like animation.(But i can not make them as video. I have to preserve every data of pixels) So i made image player using python and openCV, and it works well in usual window size(2~5K window), but as soon as i play it in fullscreen on 8K display, its frame rate drops to under 5 fps. I tried with other image formats(such as jpeg, png), but as soon as enlarge window size, it work same with bmp.

i want to know 1) why its frame rate drops in large window? 2) how can i make image player that displaying images at least 15fps on 8K window.

here's code

import numpy as np
import cv2 
import time


#variable setting

s=input('how many frames you want to play?(type in int.): ')

print('  display images in %sHz.' %s)

p=input('How many images you want to play?(type in int): ')

print('  program will read %s images.' %p)    

t=input('what is the format of images?(0:png,1:bmp,2:jpg): ')

if t=='0':
    t='png'
elif t=='1':
    t='bmp'
elif t=='2':
    t='jpg'
else:
    t='png'

print('  image format is %s.' %t)

q=input('What type of display you want?(0: FULL, 1.NORMAL, 2: AUTO): ')

if q=='0':
    cv2.namedWindow('test',cv2.WND_PROP_FULLSCREEN)
    cv2.moveWindow('test',0,0)
    cv2.setWindowProperty('test', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
    print('  FULLSCREEN MODE.')
elif q=='1':
    cv2.namedWindow('test',cv2.WND_PROP_FULLSCREEN)
    cv2.moveWindow('test',0,0)
    cv2.setWindowProperty('test', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_NORMAL)
    print('  NORMAL MODE.')
elif q=='2':
    cv2.namedWindow('test',cv2.WND_PROP_FULLSCREEN)
    cv2.moveWindow('test',0,0)
    cv2.setWindowProperty('test', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_AUTOSIZE)
    print('  AUTOSIZE MODE.')

refresh_hz = int(s) #frequency of image playing
delay = (1/refresh_hz*1000)/1000
print('interval: %.2f s' %delay)
total_img = int(p) #total number of images
count = 0 
flag = 0
start = time.time()


#image read
img = []

for i in range(1,total_img+1):
    #r_image=("./source_image/%d.%s" %(i,t))
    r_image=("./%s_img/%d.%s" %(t,i,t))
    #r_image=("./img/%d.%s" %(i,t))
    print('reading %dth image' %i)
    temp = cv2.imread(r_image)
    img.append(temp) 


print('Completed to read %d images.' %total_img)
print('It will play %d images in %dHz.' %(total_img, refresh_hz))
print("If you want to quit, hit Escape. Thanks")


#Image Player
while True:

    current = time.time()
    a= current-start

    if( a >= delay ):
        cv2.imshow('test', img[count])
        freq=1/a
        print('interval: %.3f / freq : %.3f Hz' %(a, freq))

        if(flag == 0):
            count = count +1
            if (count > total_img -2):
                flag = 1

        elif(flag == 1):
            count=count-1
            if (count < 1):
                flag = 0

        start = time.time()

    k=cv2.waitKey(1)
    if(k==27):
        break

#Quit
cv2.destroyAllWindows()
CM Lee
  • 9
  • 2
  • 1) lager window has more pixel to display so it has more work to do. – furas Mar 04 '20 at 23:21
  • it doesn't matter if you have jpeg, png or other format - it reads it to memory, uncompress and create the same image with 8K pixels. – furas Mar 04 '20 at 23:23
  • @furas So, you mean there is no way to show images much faster in larger window, don't you? – CM Lee Mar 04 '20 at 23:47
  • you may try with other module - maybe they will be faster - maybe PyQt - ie. [How to play videos in pyqt](https://stackoverflow.com/questions/57842104/how-to-play-videos-in-pyqt) or [pyglet](https://pyglet.readthedocs.io/en/latest/) which uses `OpenGL` – furas Mar 04 '20 at 23:58
  • you may also try to use Python wrapper for some video player - it may use more C/C++ code and less Python code. – furas Mar 05 '20 at 00:04

0 Answers0