Ask Your Question

How to remove detected human after DetectMultiScale?

asked 2013-11-12 10:09:03 -0600

Shaban gravatar image

Hi guys, now I'm workin on my False Human Detection projects. Can you tell me how to remove detected human after DetectMultiScale? So I can skip False Human Detection for the next frame detection.

For Example:

std::vector<cv::Rect> rects;
CascadeClassifier.detectMultiScale(frame, rects);

if(rects.size() > 0){
 for(unsigned int r = 0; r < rects.size(); r++){

I'll appreciate any help here, thanks. :)

edit retag flag offensive close merge delete


could you explain, what you mean by 'remove' ? from the vector of rects ?

also, how would you recognize a false detection ?

berak gravatar imageberak ( 2013-11-12 10:19:11 -0600 )edit

He probably knows beforehand that the image he is testing has no humans at all

Pedro Batista gravatar imagePedro Batista ( 2013-11-12 11:32:52 -0600 )edit

Yeah remove the vector of rects for detected human. I can recognize a false detection by it's color, motion, etc. for example: When a statue detected as human, I'll track the motion of detected statue. If there's no motion/movement at all, I'll remove the statue from detected human because the real human will move although only a little movement.

Shaban gravatar imageShaban ( 2013-11-13 01:23:19 -0600 )edit

rect.erase() perhaps?

GilLevi gravatar imageGilLevi ( 2013-11-13 10:21:46 -0600 )edit

I've tried that "rect.erase()" and I got an error message: "IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=cv::Rect, _Alloc=std::allocator<cv::Rect>]" matches the argument list object type is: std::vector<cv::Rect, std::allocator<cv::Rect>>"

Shaban gravatar imageShaban ( 2013-11-13 17:38:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-11-14 03:49:10 -0600

berak gravatar image

here's how you remove items from a vector:

vector<Rect>::iterator itc= rects.begin();
while (itc!=rects.end()) {
    if( NOT_A_HUMAN(*itc)) { // (*itc) is a Rect
        // erase needs an iterator, also be careful to use the returned iterator,
        //  not the previous one (that will be invalid)
        itc = rects.erase(itc); 
edit flag offensive delete link more


I've tried it, but when I bring a statue or "NOT HUMAN" things to the scene an error message show up: "Debug Assertion Failed! Expression: vector subscript out of range" I think this is a vector problem. hmmm...

Shaban gravatar imageShaban ( 2013-11-14 05:43:56 -0600 )edit

Ups sorry, it work! but sometimes show up: "Debug Assertion Failed! Expression: vector subscript out of range" :(

Shaban gravatar imageShaban ( 2013-11-14 06:02:42 -0600 )edit

Question Tools


Asked: 2013-11-12 10:09:03 -0600

Seen: 788 times

Last updated: Nov 14 '13