C# 基于EMGUcv的颜色跟踪
我正在尝试制作一个彩色物体跟踪器,它使用二值图像和斑点检测器来跟踪目标,就像这样:。但是,我无法理解ThresholdBinary()方法是如何工作的,以及它是否正确 下面是一段相关的代码:C# 基于EMGUcv的颜色跟踪,c#,video-processing,emgucv,video-tracking,C#,Video Processing,Emgucv,Video Tracking,我正在尝试制作一个彩色物体跟踪器,它使用二值图像和斑点检测器来跟踪目标,就像这样:。但是,我无法理解ThresholdBinary()方法是如何工作的,以及它是否正确 下面是一段相关的代码: cam._SmoothGaussian(3); blobDetector.Update(cam); Image<Bgr,byte> binaryImage = cam.ThresholdBinary(new Bgr(145,0,145),new Bgr(0,0,0)); Image<Gr
cam._SmoothGaussian(3);
blobDetector.Update(cam);
Image<Bgr,byte> binaryImage = cam.ThresholdBinary(new Bgr(145,0,145),new Bgr(0,0,0));
Image<Gray,byte> binaryImageGray = binaryImage.Conver<Gray,byte>();
blobTracker.Process(cam, binaryImageGray);
foreach (MCvBlob blob in blobTracker)
{
cam.Draw((Rectangle)blob, new Bgr(0,0,255),2);
}
cam.\u(3);
blobDetector.Update(cam);
图像二进制图像=cam.ThresholdBinary(新Bgr(145,0145),新Bgr(0,0,0));
Image binaryImageGray=binaryImage.Conver();
blobTracker.过程(cam,二进制图像灰色);
foreach(blobTracker中的MCvBlob blob)
{
凸轮图((矩形)水滴,新Bgr(0,0255),2);
}
当我显示binaryImage时,我甚至没有得到blob。我刚得到一张黑色的照片 通常,此类应用程序的有色斑点检测部分的工作原理如下:
// 1. Convert the image to HSV
using (Image<Hsv, byte> hsv = original.Convert<Hsv, byte>())
{
// 2. Obtain the 3 channels (hue, saturation and value) that compose the HSV image
Image<Gray, byte>[] channels = hsv.Split();
try
{
// 3. Remove all pixels from the hue channel that are not in the range [40, 60]
CvInvoke.cvInRangeS(channels[0], new Gray(40).MCvScalar, new Gray(60).MCvScalar, channels[0]);
// 4. Display the result
imageBox1.Image = channels[0];
}
finally
{
channels[1].Dispose();
channels[2].Dispose();
}
}
//1。将图像转换为HSV
使用(Image hsv=original.Convert())
{
//2.获取构成HSV图像的3个通道(色调、饱和度和值)
Image[]channels=hsv.Split();
尝试
{
//3.删除色调通道中不在[40,60]范围内的所有像素
CvInvoke.cvInRangeS(通道[0],新灰色(40).MCvScalar,新灰色(60).MCvScalar,通道[0]);
//4.显示结果
imageBox1.Image=channels[0];
}
最后
{
通道[1]。Dispose();
通道[2]。Dispose();
}
}
这正是我需要的,谢谢。事后看来,使用HSV也确实让我的生活变得轻松了很多。我有没有办法也为饱和度创建一个范围?是的,通过对饱和度通道重复上述过程,然后使用二进制和:通道[0]组合两个通道。_和(通道[1]);