0

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?

1

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.
1

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

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

    if(ret):
        if frameCount < 3:
            continue

That ended up working pretty well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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