【发布时间】:2020-04-13 12:54:45
【问题描述】:
我试图找到图像中所有轮廓的质心,但我只得到组合斑点的一个质心。如何使用所有 blob 的矩找到质心?
这是我的代码:
_blobDetector.Detect(imginput, blobs1);
blobs1.FilterByArea(100, int.MaxValue);
float scale1 = (threshedimg.Width + threshedimg.Width) / 2.0f;
_tracker.Update(blobs1, 0.01 * scale1, 5, 5);
// Bitmap drawrect = new Bitmap(threshedimg.Bitmap);
foreach (var pair1 in _tracker)
{
b1 = pair1.Value;
Emgu.CV.Util.VectorOfVectorOfPoint contour = new Emgu.CV.Util.VectorOfVectorOfPoint();
Mat heir2 = new Mat();
CvInvoke.FindContours(imginput, contour, heir2, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
for (int i = 0; i < contour.Size; i++)
{
moment = imginput.GetMoments(true);
// CvInvoke.Moments(imginput, true);
Point WeightedCentroid = new Point((int)(moment.M10 / moment.M00), (int)(moment.M01 / moment.M00));
CvInvoke.Circle(imginputcolor, WeightedCentroid, 4, new MCvScalar(0, 255, 0), 5, LineType.EightConnected, 0);
Point WeightedCentroidnew = WeightedCentroid;
CvInvoke.Line(imginputcolor, WeightedCentroid, WeightedCentroidnew, new MCvScalar(255, 0, 0), 5, LineType.EightConnected, 0);
}
imageBox1.Image = imginputcolor;
这是我得到的输出:
【问题讨论】:
标签: c# opencv image-processing emgucv