MSER Non Maxima Suppression is not supressing all the regions

asked 2017-06-15 01:50:09 -0600

ManuVISION gravatar image

updated 2017-06-15 02:11:26 -0600

I have removed non maxima regions from the vector "bbox" . But when I plot it shows the regions which still contain non maxima regions. If I measure the bbox.size() before & after non max suppression it says 4677 & 3582 respectively.Why its not able to remove all the non maximas ?? I have taken area and the start and end x & y co ordinates as the criterion.

Complete code is here: https://stackoverflow.com/questions/4...

Note: The same method in python yields much lesser regions and suppresses it all. Is there a difference between detectRegions in python & c++ ??

C++ :

Mat src = imread("/home/clabs/MANU/right_side/53.jpg",CV_LOAD_IMAGE_UNCHANGED);

Mat gray;

Mat src1 = src.clone();

cvtColor(src, gray, CV_RGB2GRAY);

Ptr<MSER> ms = MSER::create();

vector<Rect> bbox,filtered;
vector<vector<Point> > regions;
vector <int> vec;

ms->detectRegions(gray,regions,bbox);


for (int k = 0; k < bbox.size(); k++)
{
   rectangle(src,bbox[k], CV_RGB(0, 255, 0));
}

imwrite("Unsupressed.jpg",src);

cout<<bbox.size()<<"Befor Delete"<<endl;
for (int i = 0; i<bbox.size(); i++){
    for(int j = 0; j<bbox.size(); j++){

        if( (bbox[i].x > bbox[j].x) && (bbox[i].y > bbox[j].y) && ((bbox[i].x+bbox[i].width) < (bbox[j].x+bbox[j].width)) && ((bbox[i].y+bbox[i].height) < (bbox[j].y+bbox[j].height)) && (bbox[i].area() < bbox[j].area())){



            bbox.erase(bbox.begin() + i );

        }


    }
}

cout<<bbox.size()<<" After"<<endl;
cout<<vec.size()<<endl;

for (int k = 0; k < bbox.size(); k++)
{
    rectangle(src1,bbox[k], CV_RGB(255,0,0));
   //cout<<k<<endl;
}


imshow("mser", src1);
imwrite("NoN.jpg",src1);



waitKey(0);

return 0;

}

edit retag flag offensive close merge delete

Comments

your nms loop looks broken. you have to break out after removing bbox[i], because after that, bbox[i] will point to another object, and you're removing the wrong ones.

berak gravatar imageberak ( 2017-06-16 00:28:36 -0600 )edit

I tried various ways and put a break statement also. But its not working. What is the correct way of doing it ??

ManuVISION gravatar imageManuVISION ( 2017-06-24 02:03:12 -0600 )edit