0
votes

i am trying to play a video using cv2 but it's only showing one frame and the video disappears

import cv2

img_file = 'car image.jpg' video = cv2.VideoCapture('Tesla Dashcam AccidentTrim.mp4')

while True:

(read_successful, frame) = video.read()

if read_successful:
    grayscaled_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
else:
    break

classifier_file = 'car_detector.xml'

#Display the image with the faces spotted cv2.imshow('Newton Caffrey Face Detector', grayscaled_frame)

#Don't Autoclose here (wait here in the code and listen for a key press) cv2.waitKey(1)

1

1 Answers

0
votes

I used the following code for displaying the video using cv2. It will keep displaying frames untill video ends. hope this will work for you, peace!

import cv2

cap = cv2.VideoCapture("Video.mp4")

width = 400
height = 300
num = 0
while True:
    ret, frame = cap.read()
    if ret:
     frame = cv2.resize (frame, (width, height))
     cv2.imshow("frame", frame)
     if cv2.waitKey(1) & 0xff == ord('q'):
         break
cv2.destroyAllWindows()