Ask Your Question
0

Reading video from a video file not working.

asked 2017-10-15 20:04:21 -0600

ghltshubh gravatar image

updated 2020-11-09 03:45:18 -0600

supra56 gravatar image

Code:

import cv2

cap = cv2.VideoCapture('vtest.avi')

while(cap.isOpened()):

    ret, frame = cap.read()


    if(ret): 

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)


        cv2.imshow('frame',gray)
        if cv2.waitKey(1000) & 0xFF == ord('q'):
            break
    else:
        break


    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

The code runs but outputs nothing. I am using python 3 and opencv 3 on mac high sierra

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-10-15 22:12:31 -0600

supra56 gravatar image

updated 2017-10-15 22:17:33 -0600

cap = cv2.VideoCapture('vtest.avi')

# Check if camera opened successfully
if (cap.isOpened()== False): 
     print("Error opening video stream or file")

 # Read until video is completed
while(cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()
    if ret == True:

        # Display the resulting frame
        cv2.imshow('Frame',frame)

        # Press Q on keyboard to  exit
       if cv2.waitKey(25) & 0xFF == ord('q'):
           break

    # Break the loop
   else: 
       break

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

# Closes all the frames
cv2.destroyAllWindows()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-15 20:03:10 -0600

Seen: 3,754 times

Last updated: Nov 09 '20