Ask Your Question
1

How do I draw irregular contours of MSER regions

asked 2012-07-15 18:57:42 -0600

this post is marked as community wiki

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 flag offensive close merge delete

Comments

Please reformat your question in a good way!

Kirill Kornyakov gravatar imageKirill Kornyakov ( 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!

Kirill Kornyakov gravatar imageKirill Kornyakov ( 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.

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

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-07-16 02:21:58 -0600

Baris Evrim Demiroz gravatar image

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-07-15 18:57:42 -0600

Seen: 3,298 times

Last updated: Jul 18 '12