我使用c#和aforge.net查找下图中对象的周长。 Source Image
当我绘制点时,结果如下图所示。 Final Image
现在我的问题是对这些点进行排序以制作多边形并将它们之间的距离相加以找到周长。 你介意告诉我怎么做这个? 你知道找周边的更好方法吗?
private void Form1_Load(object sender, EventArgs e)
{
curImage = new Bitmap(@"1.jpg");
extractBlob(ThresholdImage(curImage));
}
Bitmap ThresholdImage(Bitmap image)
{
Bitmap result;
using (Bitmap aa = image)
{
// create grayscale filter (BT709)
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
// apply the filter
Bitmap grayImage = filter.Apply(aa);
// create filter
Threshold filter2 = new Threshold(200);
// apply the filter
filter2.ApplyInPlace(grayImage);
result = new Bitmap(grayImage);
}
return result;
}
void extractBlob(Bitmap image)
{
BlobCounterBase bc = new BlobCounter();
bc.FilterBlobs = true;
bc.MinHeight = 5;
bc.MinWidth = 5;
bc.ProcessImage(image);
Blob[] blobs = bc.GetObjectsInformation();
for (int i = 0, n = blobs.Length; i < n; i++)
{
bc.ExtractBlobsImage(image, blobs[i], true);
Bitmap copy = blobs[i].Image.ToManagedImage();
Edge(copy);
// ------> Draw Edge(copy)
}
}
List<PointF> Edge(Bitmap image)
{
// create corner detector's instance
MoravecCornersDetector mcd = new MoravecCornersDetector();
// process image searching for corners
List<IntPoint> corners = mcd.ProcessImage(image);
List<PointF> eachObject = new List<PointF>();
foreach (var item in corners)
{
PointF p = new PointF(item.X, item.Y);
eachObject.Add(p);
}
return eachObject;
}