Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I am using OpenCV 4.0.1. For 640x480 set to VedeoCapture to 1. Set to zero will be 320x480.

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()

I am using OpenCV 4.0.1. For 640x480 set to VedeoCapture to 1. Set to zero will be 320x480.

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 Or

import numpy as np
import cv2
import time

time cap = cv2.VideoCapture(1)

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

cv2.imshow('frame',gray)

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

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

cap.release()
cv2.destroyAllWindows()

cap.release() cv2.destroyAllWindows()

I am using OpenCV 4.0.1. For 640x480 set to VedeoCapture to 1. Set to zero will be 320x480.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()