cascade classification object detection

asked 2013-08-19 10:43:52 -0500

Matiz gravatar image

updated 2013-08-20 01:08:05 -0500

Siegfried gravatar image

Hello,

I have been trying to experiment with opencv functions for object detection using cascade classification. However I have not been able to get it working correctly. I have taken a simple example of cupboard door handle, which I would like to detect in images. Please find the zip of my data as attached (link - link text). This contains negative files (55 files) and positive files (66 files). The commands which I have used for the experiment are as below (I am using Ubuntu 12.10 version, along with QT Creator and Opencv libraries (2.3))

  1. find ./negatives -name '*.jpg' > negatives.dat

  2. find ./positives -name '*.jpg' > positives.dat

  3. perl createtrainsamples_my.pl positives.dat negatives.dat output (please note that I have modified the command within the perl script to use w as 10 and h as 70 (most of the positive images are apprxmt. with this ratio) (essentially the script uses the below command - opencv_traincascade -data traincascade -vec samples.vec -bg negatives.dat -numPos 66 -numNeg 55 -numStages 16 -featureType LBP -w 10 -h 70 -bt GAB -minHitRate 0.995 -maxFalseAlarmRate 0.3 -weightTrimRate 0.95 -maxDepth 1 -maxWeakCount 100 -maxCatCount 256 -featSize 1)

  4. find ./output -name '*.vec' > samples.dat

  5. mergevec samples.dat samples.vec w 10 h 70 (this i did it from windows as there were errors on Ubuntu)

  6. opencv_traincascade -data traincascade -vec samples.vec -bg negatives.dat -numPos 66 -numNeg 55 -numStages 16 -featureType LBP -w 10 -h 70 -bt GAB -minHitRate 0.995 -maxFalseAlarmRate 0.3 -weightTrimRate 0.95 -maxDepth 1 -maxWeakCount 100 -maxCatCount 256 -featSize 1

I have then renamed traincascade\cascade.xml to cascadetest2.xml in the source code as below

 #include "windowclassifier.h"
 #include "opencv2/objdetect/objdetect.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/imgproc/imgproc.hpp"

 #include <iostream>
 #include <stdio.h>

WindowClassifier::WindowClassifier()
{
}



 using namespace std;
 using namespace cv;

 /** Function Headers */
 void detectAndDisplay1( Mat frame );


 /** Global variables */
 String window_cascade_name = "cascadetest2.xml";
 CascadeClassifier window_cascade;
  string window_name1 = "Capture - Window detection";

 /** @function main */
 int main( int argc, const char** argv )
 {
   CvCapture* capture;
   //Mat frame(240,320, CV_8UC4);
   Mat frame;
   //-- 1. Load the cascades

   if( !window_cascade.load(window_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   frame = imread("/tmp/test.jpg");

   detectAndDisplay1( frame );
   return 0;
 }

/** @function detectAndDisplay */
void detectAndDisplay1( Mat frame )
{
  std::vector<Rect> faces;
  window_cascade.detectMultiScale( frame, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  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( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );


  }
  //-- Show what you got

  imshow( window_name1, frame );
  waitKey(0);


 }

I am also attaching the test data and results in this link - link text. If you see in the results, result test detected 2 handles instead of 1 and the location is offset. result test 1 did not detect anything. result test 2 detected 2 handles and the location is offset ... (more)

edit retag flag offensive close merge delete