Hello, I'm trying to make my code more efficent in context of faster FPS but seems I am getting around 35 fps or so... very slow indeed. Can someone please tell me what I have done wrong with this code that is bottlenecking it? I don't have much experience with OpenCV any help appreciated. Code will compile and execution below is from top to bottom, thanks.
//
called in main class first func
void start_camera::load_face_files(){
// Load the cascades will trip if path is not correct
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade from open cv file\n");
cout<<" \n ERROR: FILE PATH"<<face_cascade_name<<" \n NOT FOUND!"<<endl; // print error if face does not load
};
entry_func();
}
void start_camera::entry_func(){
cap.open(0);
// 0 = open default camera
int apiID = cv::CAP_ANY; // 0 = autodetect default API
// open selected camera using selected APi
cap.open(0,apiID);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
}
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
while(cap.read(frame)){
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow("live",frame);
// thread go(&start_camera::cam_start,&frame);
cam_start(frame);
// go.join();
if (waitKey(1) >= 0)
//break;
cout<<"";
}
}
void start_camera::cam_start(Mat frame){
std::vector<Rect> faces;
Mat frame_gray;
cvtColor(frame, frame_gray, COLOR_BGR2GRAY); // Convert to gray scale
equalizeHist(frame_gray, frame_gray); // Equalize histogram
// Detect faces
// face_cascade.detectMultiScale(frame_gray, faces, 1.1, 3, 0|CASCADE_SCALE_IMAGE, Size(30, 30));
// Iterate over all of the faces
for( size_t i = 0; i < faces.size(); i++ ) {
// Find center of faces
Point center(faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2);
// Draw ellipse around face
ellipse(frame, center, Size(faces[i].width/2, faces[i].height/2),
0, 0, 360, Scalar( 255, 0, 0 ), 4, 8, 0 );
}
imshow(window_name, frame); // Display frame
}