当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Draw ellipse on the center of blob

问题描述:

Hello,

I'm new C# user and I searched for easy method for drawing an ellipse on the blob, the center is blob center.

Firstly, I used OpenCvSharp.Blob name space but I could not get the center. I used Emu.CV and Aforge.Net also but the center is not achieved.

Which library can get the center in the form of X,Y?

Thanks

I used this code but also get wrong center:

foreach (Blob blob in blobs)

{

//Bitmap bitmap = (Bitmap)picConnComp.Image;

//Graphics g = Graphics.FromImage(bitmap);

Pen redPen = new Pen(Color.Red, 2);

if (blob.Rectangle.Width > 50)

{

// the blob looks interesting, let's extract it

g.DrawEllipse(redPen,

(float)(blob.CenterOfGravity.X), (float)(blob.CenterOfGravity.Y),

(float)(blob.Image.Width / 2), (float)(blob.Image.Height / 2));

}

网友答案:

If using AForge.NET framework you can get rectangle directly from blob as follows:

Rectangle rect = blob.Rectangle;

Afterwards you can draw an ellipse of blobs size like this:

...    
g1.DrawEllipse(redPen, rect);
...
分享给朋友:
您可能感兴趣的文章:
随机阅读: