我正在使用Emgucv在c#中检测整个身体。当人类坐下时,请帮助我无法察觉任何人。这就是为什么我想要检测身体的上半部分,以便当人类坐在椅子上然后可以检测到人类。我也想
了解人体检测图像的哪个部分。
public Image<Bgr, Byte> Search(Image<Bgr, Byte> image, out long processingTime)
{
processingTime = 0;
Stopwatch watch;
Rectangle[] regions;
check if there is a compatible GPU to run pedestrian detection
if (GpuInvoke.HasCuda)
{ //this is the GPU version
using (GpuHOGDescriptor des = new GpuHOGDescriptor())
{
des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());
watch = Stopwatch.StartNew();
using (GpuImage<Bgr, Byte> gpuImg = new GpuImage<Bgr, byte>(image))
using (GpuImage<Bgra, Byte> gpuBgra = gpuImg.Convert<Bgra, Byte>())
{
regions = des.DetectMultiScale(gpuBgra);
}
}
}
else
{ //this is the CPU version
using (Emgu.CV.HOGDescriptor des = new HOGDescriptor())
{
des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
watch = Stopwatch.StartNew();
regions = des.DetectMultiScale(image);
}
}
watch.Stop();
processingTime = watch.ElapsedMilliseconds;
LblProcessingTime.Text = processingTime.ToString();
foreach (Rectangle pedestrain in regions)
{
image.Draw(pedestrain, new Bgr(Color.Red), 6);
}
return image;
}
答案 0 :(得分:0)
下载并安装“haarcascade_upperbody.xml”并将其复制到bin / debug文件夹。并使用
调整代码 Image<Gray, byte> grayframe = capture.RetrieveBgrFrame().Convert<Gray, byte>();
static string HCSUpperBody = "haarcascade_upperbody.xml";
var faces = grayframe.DetectHaarCascade(hcBodyDetector, 1.2, 6, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size())[0];
foreach (var face in faces)
{
image.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 3);
}
picturebox1.image = image.toBitmap();