按照Emgu CV3+C#图像处理(一)新建一个C#控制台应用程序,然后引用相应的dll文件。
使用 HOGDescriptor()创建一个新的HOG描述符检测器,然后利用其类方法 DetectMultiScale()
示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using Emgu.CV.Util;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
String imagePath = "E:\\image\\pedestrian.jpg";
Image<Bgr, Byte> image = new Image<Bgr, byte>(imagePath);
#region use MCvObjectDetection.Rect
MCvObjectDetection[] regions;
using (HOGDescriptor des = new HOGDescriptor())
{
des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
regions = des.DetectMultiScale(image);
}
foreach (MCvObjectDetection pedestrain in regions)
image.Draw(pedestrain.Rect, new Bgr(Color.Blue), 2);
CvInvoke.Imshow("image", image);
CvInvoke.WaitKey(0);
#endregion
//#region use Rectangle
//using (HOGDescriptor des = new HOGDescriptor())
//{
// des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
// MCvObjectDetection[] regions = des.DetectMultiScale(image);
// //绘制结果
// for (int i = 0; i < regions.GetLength(0); i++)
// {
// Rectangle rectangle = regions[i].Rect;
// CvInvoke.Rectangle(image, rectangle, new MCvScalar(125, 255, 0), 2);
// }
//}
//CvInvoke.Imshow("image", image);
//CvInvoke.WaitKey(0);
//#endregion
}
}
}