简体   繁体   中英

How to get cv2.imshow() to show frames from a list?

I am trying to save the last 50 frames from my webcam into a list and then play those frames back. When I try to display the frame the display window shows gray and says it is unresponsive. If I show the frame in the while loop it displays but if i try to show the frames from the list i saved them in the above issue occurs. This is the code I am running.

cap = cv2.VideoCapture(0)
image_list = []
count = 0
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    image_list.append(frame)

    #Display the resulting frame
    #cv2.imshow('frame',frame)   <---  this will show me my live frame by frame capture

    if count >= 50:
        break

    count += 1

# When everything is done, release the capture
cap.release()

for image in image_list:  
    cv2.imshow("frame", image)
    sleep(1)

If you do not use a proper UI Framerwork like tkinter or Qt you have to call

cv2.waitKey(500)

periodically as it is the only way for the Highgui component of OpenCv to process events (and update the display). Otherwise the highgui just "hangs up".

for image in image_list:  
    cv2.imshow("frame", image)
    cv2.waitKey(500)

Excerpt from the docs :

Note

This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM