'camera dropped frame' when running detectMultiScale on OS X. I only get this error after the first loop.

asked 2014-12-07 15:26:57 -0600

atoaster gravatar image

I was running a small face detector in OS X and found that the program stopped recording and kept giving me "camera dropped frame!' error messages. I have traced the error to this line:

faceClassifier.detectMultiScale( grayFrame, faces);

which is in the function:

void findInFrame(Mat inputFrame)
{
vector<Rect> faces;
Mat grayFrame;

cvtColor(inputFrame, grayFrame, COLOR_BGR2GRAY);
faceClassifier.detectMultiScale( grayFrame, faces);


for(int i=0;i<faces.size();i++)
{
    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
    ellipse(inputFrame,center,Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

    Mat faceROI = grayFrame(faces[i]);
}
imshow("frame", inputFrame);
}

This function is called in a for loop in the main function. For some reason it works perfectly in the first run through, but during the second loop (and every loop afterwards) I get the "Camera dropped frame!" error messages, and the imshow function no longer updates the image.

I tried putting a sleep function to pause the process and slow everything down but nothing changed. How does the detectMultiScale function only work in the first run through the loop?

The main is here:

#include <iostream>
#include <unistd.h>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>


using namespace std;
using namespace cv;

string faceHaar = "haarcascade_frontalface_alt.xml";
string eyesHaar = "haarcascade_eye.xml";

CascadeClassifier faceClassifier
void findInFrame(Mat inputFrame);

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

VideoCapture cam(0);
Mat frame;

if(!faceClassifier.load(faceHaar))
{
    cout << "Error loading face cascade" << endl;
    return -1;
}

for(;;)
{
    cam >> frame;

    if(!frame.empty())
    {
        findInFrame(frame);
        //usleep(1000);
    }
    else
    {
        cout << "frame empty" << endl;
    }
}

return 0;
}
edit retag flag offensive close merge delete