# How do I draw irregular contours of MSER regions

This post is a wiki. Anyone with karma >50 is welcome to improve it.

How I can draw the contour of MSER regions which I have detected ? //detect MSER regions,Ellipse fitting of MSER regions,draw contour of MSER region//

int main(int argc, char *argv[]) {

Mat box = imread("box.png",1);
MSER ms;
vector<vector<Point>> regions;
ms(box, regions, Mat());
for (int i = 0; i < regions.size(); i++)
{
ellipse(box, fitEllipse(regions[i]), Scalar(255));
}
imshow("mser", box);
waitKey(0);
return 0;


}

//Next step I try to draw irregular contour of MSER regions which have been detected by the above code. This step I write code as follow://

int main(int argc, char *argv[]) {

Mat box = imread("box.png",1);
MSER ms;
vector<vector<Point>> regions;
ms(box, regions, Mat());
for (int i = 0; i < regions.size(); i++)
{
ellipse(box, fitEllipse(regions[i]), Scalar(255));
drawContours(box,regions,i,Scalar(0,255,255),1,8);//this was used to draw
//irregular  outlines of MSER regions
}
imshow("mser", box);
waitKey(0);
return 0;


}

The result of above code show that the irregular interiors of MSER regions are drawn. But, I just need draw irregular contour(outline) of MSER regions, not interiors, how I need use the function of drawContours, what should I do?

a kind friend, imran, recommmend me use the function drawcontour like this:

drawContours(box,regions,i,Scalar(0,255,255),1,8, vector<vec4i>(), 0, Point());//this was used to draw irregular outlines of MSER regions//

However,it still show that the function draws the contour(s) and all the nested contours, I just want draw contour, not nested contours,so it does not work. I do not know whether I have explain my problem clear?

edit retag close merge delete

( 2012-07-18 06:49:51 -0600 )edit

1). Question name is still bad, you should remove the noise from the beginning. 2). Not all code is formatted as a code. 3). You should use spaces after commas. 4). You should probably attach some images. Please try again!

( 2012-07-18 06:56:19 -0600 )edit

One mser region, what you get from opencv, contains all points that are belong to one extracted region. So mser region is not a contour of the region. You can find the outer contour by going through every pixels of one region. Find minX and maxY for every Y value that are present in one region. So the result will be an outer contour.

( 2013-07-10 12:24:16 -0600 )edit

Sort by ยป oldest newest most voted

To draw outlines, you should set the thickness parameter of drawContours() to 1 (or some other value >0).

int allContours = -1;
int thickness=1;
drawContours(img, contours, allContours, Scalar::all(255), thickness);


If this does not work, can you post how you are calling drawContours()?

PS You can always upload photos to a third party service like imgur.

more

Official site

GitHub

Wiki

Documentation