EmguCV HOG描述符总是为零

时间:2017-03-07 09:38:26

标签: c# emgucv

我正在尝试从图像中提取HOG描述符,但结果总是得到零。怎么解决呢这是我用来提取HOG描述符的C#代码。

private void btnGetHOGDescriptor_Click(object sender, EventArgs e)
{
    if(InputImage.Original != null)
    {
        Image<Bgr, Byte> inputImage = new Image<Bgr, Byte>(new Bitmap(pbInputImage.Image));
        float[] descriptor = GetVector(inputImage);

        rtbDescriptor.Text = string.Join(" ", descriptor);
    }
}

public float[] GetVector(Image<Bgr, Byte> img)
{
    HOGDescriptor hog = new HOGDescriptor();    // with defaults values
    Point[] p = new Point[img.Width * img.Height];
    int k = 0;
    for (int i = 0; i < img.Width; i++)
    {
        for (int j = 0; j < img.Height; j++)
        {
            Point p1 = new Point(i, j);
            p[k++] = p1;
        }
    }

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

1 个答案:

答案 0 :(得分:0)

如果您将GetVector更改为:

public float[] GetVector(Image<Bgr, Byte> img)
        {
            HOGDescriptor hog = new HOGDescriptor();    // with defaults values

            return hog.Compute(img, new Size(8, 8), new Size(0, 0), null);
        }