Performance of Raspberry Pi with OpenCV

When working with robotics, physical space requirements are always a priority. Small and readily available Linux boards now have the capabilities to perform computer vision. The most famous, is the Raspberry Pi; it contains a 700Mhz ARM processor and has become very popular with robotics and electronics; this cost effective board has now brought computer vision into lower scale robotics projects that would not have before, but how much can we expect from it? What is its performance? And how will different algorithms effect the frame rate?

I will be doing the timing test on the Raspberry Pi in Arch Linux; for more information on why and how, see this post:

OpenCV On Raspberry Pi with Arch Linux

A Logitech webcam will be used for these tests rather than the camera board for the Raspberry Pi; performance looks like it will be increased from using it, where more information can be seen below:

Raspberry Pi Camera Board

I will be running 320 by 240 pixel and 640 by 480 pixel images to see how they perform and how much the frame rate is affected by how many iterations of filtering. I am going to implement my own written functions and also use OpenCV’s to compare the timing difference. To improve speed I did not display images to screen for any of the tests, here is the base line sample code used:

#include "cv.h" #include "highgui.h" #include <stdio.h> #include <unistd.h> main( int argc, char* argv[] ) { //initialize variables double fps = 0, sec = 0; int counter=0; time_t startTime, endTime; //capture video from webcam CvCapture* capture = cvCreateCameraCapture(0); assert( capture != NULL ); //initialize image pointers IplImage *frame, *output, *edge; //grab first frame to extract data frame = cvQueryFrame(capture); int width = frame->width; int height = frame->height; //start timer time(&startTime); output = cvCreateImage(cvSize(width, height), IPL_DEPTH_8u, 1); edge = cvCreateImage(cvSize(width, height), IPL_DEPTH_8u, 1); while(1) { frame = cvQueryFrame(capture); //break when out of frame if(!frame) break; ///------------------------------main loop--------------------------- //Filters go here ///------------------------------end main loop----------------------- //take time time(&endTime); ++counter; if(counter%100==0) { sec=difftime(endTime,startTime); fps=counter/sec; printf("%f

",fps); } //wait in mili seconds usleep(30000); } //cvReleaseImage(&frame); cvReleaseCapture(&capture); return(0); }

Edit: An extension of this experiment with motion detection can be seen here:

Motion Detection on the Raspberry Pi

The code I will be adding for the tests will be between the main loop comments above, algorithm tested will add 1 iteration of cycle through the image; to see the code used for the test see link below:

Simplified Functions for OpenCV

The lower frame rate is from showing darker images (almost black) where the higher frame rate is from lighter images (almost white), the reason why the drastic difference in frame rate is not confirmed, but assuming it is relevant to processing the image, e.g. higher ISO of the camera means more gain required in the image; this shows that if possible more emphasis on lighting will result in drastically improved performance. The test results are below:

—————————————————————————————————————————–

• 320×240 no filtering: 8 to 17.6fps

• 640×480 no filtering: 7.4 to 11.6fps

—————————————————————————————————————————–

• 320×240 1 iteration convert to grayscale: 7.7 to 17.6 fps

• 640×480 1 iteration convert to grayscale: 7.3 to 11.7 fps

• 320×240 cvCvtColor(): 7.6 to 16.7 fps

• 640×480 cvCvtColor(): 7.3 to 10 fps

—————————————————————————————————————————–

• 320×240 2 iterations convert to grayscale->edge detection: 7.7 to 17.5 fps

• 640×480 2 iterations convert to grayscale->edge detection: 7.4 to 11.5 fps

• 320×240 cvCvtColor(); cvSobel(): 7.5 to 12.5 fps

• 640×480 cvCvtColor(); cvSobel(): 5.4 to 5.5 fps

—————————————————————————————————————————–

• 320×240 3 iterations convert to grayscale->edge detection->threshold: 7.7 to 17.5 fps

• 640×480 3 iterations convert to grayscale->edge detection->threshold: 7.4 to 11.5 fps

• 320×240 opencv cvCvtColor(); cvSobel(); cvThreshold(): 7.5 to 12.2 fps

• 640×480 opencv cvCvtColor(); cvSobel(); cvThreshold(): 5.3 to 5.3 fps

—————————————————————————————————————————–