使用来自EMGU CV C#的HOGDescriptor获取图像的HOG描述符

时间:2013-12-10 15:01:29

标签: c# image-processing emgucv pattern-recognition

如何使用EMGU CV和C#计算图像的猪描述符向量。

如果我做这样的事情:

float[] f;
Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(fullPath);

f = hog.Compute(img1, Size.Empty, Size.Empty,null );

它不起作用,它给出了

  

对象引用未设置为对象的实例。

异常。我想用默认参数计算hog描述符。

有人知道怎么做吗?

Emgu cv记录很差。

我修改了代码,现在我收到以下错误:“外部组件抛出了异常”代码列在下面

public float[] GetVector(Image<Bgr, Byte> im)
    {
        HOGDescriptor hog = new HOGDescriptor();    // with defaults values
       // Image<Bgr, Byte> pImage = new Image<Bgr, Byte>(;
       //pImage.ROI = new Rectangle(new Point(0, 0), new Size(64, 128));
        Point[] p = new Point[im.Width * im.Height];
        int k = 0;
        for (int i = 0; i < im.Width; i++)
        {
            for (int j = 0; j < im.Height; j++)
            {
                Point p1 = new Point(i, j);
                p[k++] = p1;
            }
        }
        return hog.Compute(im, new Size(8, 8), new Size(0, 0), p);
    }

1 个答案:

答案 0 :(得分:4)

这里的记录是他回答:

public Image<Bgr, Byte> Resize(Image<Bgr, Byte> im)
        {
            return im.Resize(64, 128, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
        }
        public 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);
        }

如果其他人需要它:)

相关问题