'camera dropped frame!' error messages when running detectMultiScale.

asked 2014-12-07 15:39:20 -0600

atoaster gravatar image

Strangely enough, I only get this error message after running the first loop.

The main function calls this function I made:

 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);
}

and when it hits the detectMultiScale line it outputs "Camera dropped frame!" to the console. The imshow line no longer updates after that point. This function is called from my main in a for loop. For some reason it runs fine the first time through but on the second loop it gives me the error.

Does anyone know why this is happening? Thanks in advance.

The full main code 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