Hello everybody. I made a project with OpenCV in c++ using eclipse to detect fire extinguisher. I took 1000 images with camera and while applying detection on video, it works great. But right now i want to do detection on static images to calculate accuracy of detection. Problem is when I apply detection on static images, it doesn't work (red bounding rectangle is not shown on images). Here's the code I use (just picked out the relevant lines):
int main() {
cvNamedWindow("fire_extinguisher detecting camera", 1);
// Capture images from any camera connected to the system
CvCapture* capture = cvCaptureFromAVI("/home/painkiller/Desktop/videos_krstionica/1.mp4");
// Load the trained model
CascadeClassifier fire_extinguisherDetector;
fire_extinguisherDetector.load("src/krstionica.xml");
if (fire_extinguisherDetector.empty()) {
printf("Empty model.");
return 0;
}
char key;
while (true) {
for(int i=0; i < 1000; i++)
{
Mat frame;
String result;
String beginning;
String end;
beginning = "/home/painkiller/Desktop/dada/";
end = ".jpg";
std::stringstream sstm;
sstm << beginning << i << end;
result = sstm.str();
frame = imread(result); // THIS IS USED NOW FOR IMAGE DETECTION
// frame = cvQueryFrame(capture); // THIS WAS USED FOR VIDEO DETECTION
stringstream x,y;
std::vector<Rect> fire_extinguishers;
fire_extinguisherDetector.detectMultiScale(frame, fire_extinguishers, 1.10,1,
0 | CV_HAAR_SCALE_IMAGE, Size(50, 450));
for (int i = 0; i < (int) fire_extinguishers.size(); i++) {
Point pt1(fire_extinguishers[i].x, fire_extinguishers[i].y);
Point pt2(fire_extinguishers[i].x + fire_extinguishers[i].width,
fire_extinguishers[i].y + fire_extinguishers[i].height);
// Draw a rectangle around the detected object
rectangle(frame, pt1, pt2, Scalar(0, 0, 255), 2);
}
// Show the transformed frame
if (!frame.empty())
imshow("fire_extinguisher detecting camera", frame);
waitKey(3000);
// Read keystrokes, exit after ESC pressed
key = cvWaitKey(10);
if (char(key) == 27) {
break;
}
}
return 0;
} }
I also tried with cvCaptureFromFile:
CvCapture* capture = cvCaptureFromFile("/home/painkiller/Desktop/dada/1.jpg");
frame = cvQueryFrame(capture);
But that didn't work either...