Ask Your Question
0

i want the frame evey second from the stream of my webcam?

asked 2019-01-31 06:32:36 -0600

I am doing a project in python and i want the every second frame from the steam of my webcam.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-01-31 08:23:14 -0600

supra56 gravatar image

updated 2019-01-31 08:25:29 -0600

I am using OpenCV 4.0.1. For 640x480 set to VedeoCapture to 1. Set to zero will be 320x480. I am using raspberry pi 3B/+, Linus.

import cv2

cap = cv2.VideoCapture(1)
count = 0

while cap.isOpened():
    ret, frame = cap.read()

    if ret:
        cv2.imwrite('frame{:d}.jpg'.format(count), frame)
        count += 30 # i.e. at 30 fps, this advances one second
        cap.set(1, count)
    else:
        cap.release()
        break

Or

import numpy as np
import cv2
import time

cap = cv2.VideoCapture(1)

while True:
    start_time = time.time()
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)

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

    time.sleep(1.0 - time.time() + start) 

cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-01-31 06:32:36 -0600

Seen: 3,089 times

Last updated: Jan 31 '19