【发布时间】:2016-08-21 03:00:06
【问题描述】:
我在使用 EmguCV 从图像中提取 blob 时遇到一些问题。我在网上看到的所有东西都使用 Contours 对象,但我猜想它是从 EmguCV3.0 中删除的?每次尝试使用它时都会出现异常。我没有发现很多最近的/相关的 SO 主题并没有过时。
基本上,我有一张叶子的照片。背景可能是白色、绿色、黑色等。我想从根本上移除背景,以便我可以在不干扰背景的情况下对叶子执行操作。我只是不确定我要去哪里错了:
Image<Bgr, Byte> Original = Core.CurrentLeaf.GetImageBGR;
Image<Gray, Byte> imgBinary = Original.Convert<Gray, Byte>();
imgBinary.PyrDown().PyrUp(); // Smoothen a little bit
imgBinary = imgBinary.ThresholdBinaryInv(new Gray(100), new Gray(255)); // Apply inverse suppression
// Now, copy pixels from original image that are black in the mask, to a new Mat. Then scan?
Image<Gray, Byte> imgMask;
imgMask = imgBinary.Copy(imgBinary);
CvInvoke.cvCopy(Original, imgMask, imgBinary);
VectorOfVectorOfPoint contoursDetected = new VectorOfVectorOfPoint();
CvInvoke.FindContours(imgBinary, contoursDetected, null, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
var contoursArray = new List<VectorOfPoint>();
int count = contoursDetected.Size;
for (int i = 0; i < count; i++)
{
using (VectorOfPoint currContour = contoursDetected[i])
{
contoursArray.Add(currContour);
}
}
有了这个,我得到一个带有一点点白线的黑色图像。我来回绞尽脑汁,也想不出什么来。任何指针将不胜感激!
【问题讨论】:
标签: opencv image-processing emgucv