c# - 用于人员检测的 Emgu 训练 SVM - C#

标签 c# opencv image-processing svm emgucv

我在网上搜索了很多,找不到任何简单的解决方案。

我正在尝试创建一个人员检测器,为此我选择了 Emgu 库。

目前我能够检测到人,但成功率不高。

我正在尝试训练我的 SVM,我在这篇文章中看到:SVM classifier based on HOG features for “object detection” in OpenCV我需要培训的过程:

Step 1) Prepare some training images of the objects you want to detect (positive samples). Also you will need to prepare some images with no objects of interest (negative samples).

Step 2) Detect HOG features of the training sample and use this features to train an SVM classifier (also provided in OpenCV).

Step 3) Use the coefficients of the trained SVM classifier in HOGDescriptor::setSVMDetector() method.

我有一些训练图像,我正在使用这行代码来提取 HOG 特征:

public static Image<Bgr, Byte> Resize(Image<Bgr, Byte> im)
    {
        return im.Resize(64, 128,   Inter.Linear);
    }
    public static float[] GetVector(Image<Bgr, Byte> im)
    {
        HOGDescriptor hog = new HOGDescriptor();    // with defaults values
        Image<Bgr, Byte> imageOfInterest = Resize(im);
        Point[] p = new Point[imageOfInterest.Width * imageOfInterest.Height];
        int k = 0;
        for (int i = 0; i < imageOfInterest.Width; i++)
        {
            for (int j = 0; j < imageOfInterest.Height; j++)
            {
                Point p1 = new Point(i, j);
                p[k++] = p1;
            }
        }

        return hog.Compute(imageOfInterest, new Size(8, 8), new Size(0, 0), p);
    }

但我找不到如何训练我的 SVM(上述步骤中的第 2 步)。

最佳答案

我已经做到了。 注意:它有一些我还没有用太多 HoG 特性解决的问题。

代码是:

//GetVector - function from people detection file 
float[] hog = GetVector(new Image<Bgr, byte>(image));

 svm.TrainAuto(new TrainData(training_mat, Emgu.CV.ML.MlEnum.DataLayoutType.RowSample, lables));

关于c# - 用于人员检测的 Emgu 训练 SVM - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37028423/

相关文章:

c# - 如何使用 StreamWriter 编辑/替换 .txt 文件中的特定值?

python - 在 Python 中将 knnMatch 与 opencv 一起使用时出错

c++ - 如何以优雅的方式使用 OpenCV、C++ 检索偶数/奇数索引中的值?

opencv - 在使用 OpenCV 进行图像拼接时遇到一些困难

c++ - 抛出 'cv::Exception' 的实例后,OpenCV 中出现错误标志错误。 cvGetMat 中不支持的数组类型

opencv - 查找重复图像的软件链

c# - C#'s operators' 操作顺序

c# - 线程与任务中的 ThreadStatic 属性

Python 图像处理 : Measuring Layer Widths from Electron Micrograph

c# - 实体架构