Low capture rate

Hi sir,
Here is my code for Face detection and its performance in Beagleboard.

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "cv.h"

//#include "highgui.h"
#include <iostream>
#include <stdio.h> // A Simple Camera Capture Framework

using namespace std;
using namespace cv;
int isColor = 1;
int frameW = 320;
int frameH = 240;

void detectAndDraw( Mat& img,
                   CascadeClassifier& cascade, CascadeClassifier&
nestedCascade,
                   double scale);

String cascadeName =
"../../data/haarcascades/haarcascade_frontalface_alt.xml";
String nestedCascadeName =
"../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml";

int main(int argc, const char** argv ) {

  //CvCapture* capture = 0;
  double scale = 1;
  //CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
  CvCapture* capture = cvCreateCameraCapture(-1);
        Mat frame, frameCopy, image;
        const String scaleOpt = "--scale=";
        size_t scaleOptLen = scaleOpt.length();
        const String cascadeOpt = "--cascade=";
        size_t cascadeOptLen = cascadeOpt.length();
        const String nestedCascadeOpt = "--nested-cascade";
        size_t nestedCascadeOptLen = nestedCascadeOpt.length();
        String inputName;
      CascadeClassifier cascade, nestedCascade;

  if( cascadeOpt.compare( 0, cascadeOptLen, argv[1], cascadeOptLen ) ==
0 )
        {
            cascadeName.assign( argv[1] + cascadeOptLen );
            cout << " from which we have cascadeName= " <<
cascadeName << endl;
        }

  cascade.load( cascadeName );

  if(!capture){
  fprintf(stderr,":-).Cheerrrrrrrrrrrrrrrrrrrrr\n");

   return -1;

  }
  IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read

  //double fps = cvGetCaptureProperty(&capture,CV_CAP_PROP_FPS);

  CvSize size = cvSize((int)cvGetCaptureProperty( capture,
CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty( capture,
CV_CAP_PROP_FRAME_HEIGHT) );

  //CvVideoWriter *writer =
cvCreateVideoWriter("out.avi",CV_FOURCC('D', 'I', 'V', 'X'),15, size,
isColor);
  CvVideoWriter *writer =
cvCreateVideoWriter("out.avi",CV_FOURCC('I','Y','U','V'),
15,size,isColor);
//CvVideoWriter *writer = cvCreateVideoWriter("out.avi",CV_FOURCC('U',
'2', '6', '3'),5,size,isColor);

  if (writer != NULL)
  fprintf(stderr,":-).Cheerrrrrrrrrrrrrrrrrrrrr\n");
  else fprintf(stderr,":-(\n");

   // Create a window in which the captured images will be presented
   //cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );

  IplImage* logpolar_frame = cvCreateImage(size,IPL_DEPTH_8U,3);

  while( (bgr_frame=cvQueryFrame(capture)) != NULL )
  {
     cvWriteFrame( writer, bgr_frame );
    //cvShowImage( "mywindow", bgr_frame );
    //cvFlip( bgr_frame, frameCopy, 0 );
    frameCopy = bgr_frame;
    detectAndDraw( frameCopy, cascade, nestedCascade, scale);
      // Do not release the frame! //If ESC key pressed,
Key=0x10001B under OpenCV 0.9.7(linux version), //remove higher
bits using AND operator
      if( (cvWaitKey(10) & 255) == 27 )
     break;

  }

  cvReleaseVideoWriter( &writer );

  //cvReleaseImage( &logpolar_frame );

  cvReleaseCapture( &capture );
    //cvDestroyWindow( "mywindow" );

  return(0);

}

void detectAndDraw( Mat& img,
                   CascadeClassifier& cascade, CascadeClassifier&
nestedCascade,
                   double scale)
{
    int i = 0;
    double t = 0;
    vector<Rect> faces;
    const static Scalar colors[] = { CV_RGB(0,0,255),
        CV_RGB(0,128,255),
        CV_RGB(0,255,255),
        CV_RGB(0,255,0),
        CV_RGB(255,128,0),
        CV_RGB(255,255,0),
        CV_RGB(255,0,0),
        CV_RGB(255,0,255)} ;
    Mat gray, smallImg( cvRound (img.rows/scale), cvRound(img.cols/
scale), CV_8UC1 );

    cvtColor( img, gray, CV_BGR2GRAY );
    resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR );
    equalizeHist( smallImg, smallImg );

    t = (double)cvGetTickCount();
    cascade.detectMultiScale( smallImg, faces,
        1.1, 2, 0

Hi,

640x480 is usually slow. If you try displaying the results, it will be using up precious processing power… Once yu have designed the code may be u can change the GUI display to just notifications in “Terminal” showing no of detections and so on…

By the way how did u compile the code??
Used g++? What was the command you used to compile this code??

Thanks

Hmm… isn’t this a homework question / assignment ??

Cortex-A8 in BB, gives one 1200DMIPS, and in xM gives one 2000DMIPS. That’s a tremendous amount of computational power. Folks have managed to Face-detection on ~60DMIPS ARM7TDMIs, at much better rate albeit for smaller framesize, but extrapolate it, and one should still be able to an awful lot in 1200DMIPS. On ARM7TDMI, weren’t using OpenCV :-), however given how well OpenCV is optimized (supposedly), VGA face-detection being “usually slow” indicates some inherent issues, either in the use of the API, or the library itself.

Jayanth Acharya wrote:

Hmm... isn't this a homework question / assignment ??

it's 2011, crowdsourcing is the way to go...

Cortex-A8 in BB, gives one 1200DMIPS, and in xM gives one 2000DMIPS. That's a tremendous amount of computational power.
Folks have managed to Face-detection on ~60DMIPS ARM7TDMIs, at much better rate albeit for smaller framesize, but
extrapolate it, and one should still be able to an awful lot in 1200DMIPS. On ARM7TDMI, weren't using OpenCV :-),
however given how well OpenCV is optimized (supposedly), VGA face-detection being "usually slow" indicates some inherent

how much is OpenCV "supposedly" optimized on ARM?