Ask Your Question

Rafael's profile - activity

2014-11-30 22:02:49 -0600 asked a question OpenCV on Beaglebone Black - select timeout after 4 minutes

I'm using BBB, Ubuntu 14.04, OpenCV 2.4.9 and Microsoft LifeCam HD-5000. When I start my program everything works well and fast, but after 4 minutes running the program start to show the message "select timeout" and run so slow to get new frames.

See my code:

int main(){
const unsigned int SENSOR_GPIO = 51;

VideoCapture videoCapture;
long timer;
unsigned int presenceSensor;
Mat frame;

CascadeClassifier faceCascade;
vector<Rect> faces;

faceCascade.load("/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml");

gpio_export(SENSOR_GPIO);
gpio_set_dir(SENSOR_GPIO, INPUT_PIN);

while( true )
{
    gpio_get_value(SENSOR_GPIO, &presenceSensor);

    if( presenceSensor == 1 )
    {
        timer = time(0);

        videoCapture.open(-1);

        while( (time(0) - timer) < 30 )
        {
            videoCapture >> frame;
            cvtColor(frame, frame, CV_BGR2GRAY);

            faceCascade.detectMultiScale(frame, faces, 1.1, 2,0 | CV_HAAR_SCALE_IMAGE, Size(100,100), Size(500,500));

            if( faces.size() > 0 ){
                cout << "Face detected..." << endl;
            }
            else{
                cout << "face not detected" << endl;
            }
        }

        videoCapture.release();
    }
    else {
        sleep(1);
    }
}

return 0;

}

The problem seems a failed in memory management, but I don't know how to optimize this code, it is already so clean.

Thank you all.