lewis321
Posts: 5
Joined: Tue Jun 17, 2014 1:54 am

video update rate is too slow when using openCV

Sun Jun 22, 2014 2:03 am

Hi, I buy a camera module from net and install and setup it according to the video:
http://www.raspberrypi.org/help/camera-module-setup/
My camera module is the same as that in this video. After the installation of openCV on Pi, I use following command to start my camera module:
sudo modprobe bcm2835-v4l2
Then, I run the following openCV code:

Code: Select all

import cv

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)

def repeat():
    global capture #declare as globals since we are assigning to them now
    global camera_index
    frame = cv.QueryFrame(capture)
    cv.ShowImage("w1", frame)
    c = cv.WaitKey(10)
    if(c=="n"): #in "n" key is pressed while the popup window is in focus
        camera_index += 1 #try the next camera index
        capture = cv.CaptureFromCAM(camera_index)
        if not capture: #if the next camera index didn't work, reset to 0.
            camera_index = 0
            capture = cv.CaptureFromCAM(camera_index)

while True:
    repeat()
Then, I can see the window displaying video, but its update frequency is too slow, about 0.2Hz. It needs 5 seconds to update one frame!!! I guess it might be the reason of its high resolution. I do not need high resolution. I only need high update frequency, at lest 10Hz. How to solve my problem? Thank you.

lewis321
Posts: 5
Joined: Tue Jun 17, 2014 1:54 am

Re: video update rate is too slow when using openCV

Sun Jun 22, 2014 2:52 am

To show my problem better, I recorded a video and you can watch it here:
https://www.dropbox.com/s/t7n2lwr6ceze9 ... quency.wmv
From this video, you can clearly see that its update frequency is too slow.
Thank you.

lewis321
Posts: 5
Joined: Tue Jun 17, 2014 1:54 am

Re: video update rate is too slow when using openCV

Sun Jun 22, 2014 3:15 am

This is what I get when using "lsmod" command:

https://www.dropbox.com/s/t3eahyr5skz41qw/lsmod.jpg

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8462
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: video update rate is too slow when using openCV

Sun Jun 22, 2014 11:44 am

I did a load of investigation into OpenCV and getting it to work with the V4L2 driver. There are a bundle of posts starting from about http://www.raspberrypi.org/forums/viewt ... 2s#p528389

The main thing was that OpenCV was setting the framerate to 30fps, but was then unable to keep up with the results. Manually setting a lower framerate meant it kept up and significantly reduced the latency. There appeared not to be a way to do that programmatically from OpenCV.
There was also a change to support BGR24 so that OpenCV wasn't doing the conversion from YUV (or worse still MJPEG) on the ARM. Have you done an rpi-update recently to get the latest changes? (These were actually probably about 2 months back, so it isn't that recent in reality). Run the terminal command v4l2-ctl -V will tell you what format V4L2 is delivering to your application.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”