I am using the following command to take video:

os.popen('raspivid -1 640 -h480 -fps 25 -o motionCapture/' + timeStamp + '_motion,h264 -t ' + str(timeInSeconds * 1000))

The problem is when I try to compare frames for motion detection (or any other comparisons using openCV), the camera is still adjusting in the first couple of frames and it throws everything off. How can I add in a delay before the camera starts actually saving the video to the file I specified?


A coupla' thoughts:

  1. There are some potentially useful options in raspivid

    • --timed, -td Do timed switches between capture and pause
    • --framerate, -fps Specify the frames per second to record

NOTE: 2 < -fps < 30

  1. The Picamera module is made for Python, seems to offer better documentation, and an extensive interface.

I ended up comparing to the previous frame rather than the first frame so there was no need for a delay. I also switched to cv2.VideoCapture. But before I made those changes I added something like this:

frameCount = 0

    ret,frame = cap.read()
    frameCount += 1

        if frameCount < 3:

That ended up working pretty well.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.