Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You wanted to count frame by frame?

#!/usr/bin/python3.7

import cv2
cap = cv2.VideoCapture("road.avi")
fps = cap.get(cv2.CAP_PROP_FPS)
Frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

frame_counter = 0
frame_by_frame=[] 

while cap.isOpened():
    ret, frame = cap.read()
    frame_by_frame.append(frame_counter)
    print(f'number of frames: ' + str(len(frame_by_frame)))
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
        cap.release()
        cv2.destroyAllWindows()

You wanted to count frame by frame?

#!/usr/bin/python3.7

import cv2
cap = cv2.VideoCapture("road.avi")
cv2.VideoCapture('video.wmv')
fps = cap.get(cv2.CAP_PROP_FPS)
Frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

frame_counter = 0
frame_by_frame=[] 

while cap.isOpened():
    ret, frame = cap.read()
    frame_by_frame.append(frame_counter)
    print(f'number of frames: ' + str(len(frame_by_frame)))
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
        cap.release()
        cv2.destroyAllWindows()

You wanted to count frame by frame?

#!/usr/bin/python3.7

import cv2
cap = cv2.VideoCapture('video.wmv')
fps = cap.get(cv2.CAP_PROP_FPS)
Frames frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

frame_counter = 0
frame_by_frame=[] 

while cap.isOpened():
    ret, frame = cap.read()
    frame_by_frame.append(frame_counter)
    print(f'number of frames: ' + str(len(frame_by_frame)))
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
        cap.release()
        cv2.destroyAllWindows()