Problem with detectMultiScale and drawing returned rectangles [closed]

asked 2016-06-16 09:26:47 -0600

I trained a cascade classifier to detect pencils/pens. The cascade is quit ok, i assume.

I have following Problems:

  1. detectMultiScale(...) does not detect pens as separate objects if they are close together.

  2. The produced Rectangles by detectMultiScale(...) do not bound the object if i draw the Rectangles. Either i draw the recs wrong or detectMultiScale(...) does something wrong. (see pictures for 1. and 2.).

  3. Or is my cascade classifier shit?

The relevant code(the other stuff are just simple checks like is videocapture open and such, nothing relevant to the Problem):

 while(true){¬                                                                    
      Mat frame;¬                                                                  
      cap >> frame;¬ 
      detectPencils(frame);¬
      .....
      int c = waitKey(35);¬                                                        
      if( (char)c == 27 ) {¬                                                       
          break;¬                                                                  
      }¬                                                                           
 }¬       
void detectPencils(Mat frame) {¬                                             
        vector<Rect> pencils_bb;¬                                                        
        Mat frame_gray;¬                                                                 
       cvtColor( frame, frame_gray, COLOR_BGR2GRAY);¬                                   
       //denoise¬                                                                       
        Mat denoised;¬                                                                   
       fastNlMeansDenoising(frame_gray, denoised, 10, 7, 21); ¬                         
       //Detect pencils¬                                                                 
       pencil_cascade.detectMultiScale( denoised, pencils_bb, 1.05, 3, 0, Size(5,40));
       imshow("denoised", denoised);¬                                                   
       for( size_t  i = 0; i < pencils_bb.size(); i++ ) {¬                              
            rectangle(frame, pencils_bb[i].tl(), pencils_bb[i].br()-Point(1,1), Scalar( 0, 0, 255), 1, 8, 0);
       }¬                                                                               
       imshow("bbs", frame);¬                                                   ¬                                                                
}¬

Pictures Problem 1: ok:image description

not ok:

image description


Pictures Problem 2: ok image description

not ok

image description

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-08 02:14:43.419317