Ask Your Question
1

Show video after few seconds [closed]

asked 2018-10-16 03:44:12 -0500

doudouou gravatar image

Hello How can I show (on screen) the webcam video with a time lag of few seconds? I'm sport's'coach and I want to film my players and show them their actions "in live" with a video projector. I'm using python and I've just discover opencv.

Sorry for my language; I'm french...

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by doudouou
close date 2018-10-16 08:37:47.013987

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-10-16 05:24:47 -0500

berak gravatar image

if you really meant "few seconds", you can use a ringbuffer, or python's builtin Queue for this. (else it will need far too much memory, and then you should write short videos to disk instead):

import cv2
import numpy as np

import queue # Queue in 2.7 !


def main():
    fps = 25
    nseconds = 5 # delay
    ring = queue.Queue(fps * nseconds)

    cap = cv2.VideoCapture(0)
    if not cap.isOpened():
        print("capture did not open!")
        return

    while(True):
        ret,frame = cap.read()
        if not ret: ## someone stepped on the cable ?
            print("no frame")
            break

        ring.put(frame)
        if ring.full():
            src = ring.get()
            cv2.imshow('src', src)

        k = cv2.waitKey(int(1000.0/fps))
        if k==27: break ## esc. pressed

if __name__ == "__main__":
    main()

(try it anyway, it's a fun prog !)

edit flag offensive delete link more

Comments

Yes!! It's exactly what I want. Thanks a lot. I try with fullscreen and 30 seconds. Perfect!

doudouou gravatar imagedoudouou ( 2018-10-16 08:36:38 -0500 )edit

just don't forget to do the maths: ram_needed = fps * nseconds * width * height * 3

berak gravatar imageberak ( 2018-10-16 08:40:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-16 03:44:12 -0500

Seen: 658 times

Last updated: Oct 16 '18