Taking the HOG descriptor of an image using HOGDescriptor from EMGU CV C#

女生的网名这么多〃 提交于 2019-12-06 11:16:42

问题


How can I compute the hog descriptor vector of an image using EMGU CV and C#.

If i make something like this:

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

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

it doesn't work, it gives a

Object reference not set to an instance of an object.

exception. I want to compute the hog descriptor with default parameters.

Does someone know how to do this ?

Emgu cv is very poorly documented.

I have modified the code and now I am getting the following error: "External component has thrown an exception" The code is listed below

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:


Just for the record here is he answer:

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);
        }

If someone else will ever need it :)



来源:https://stackoverflow.com/questions/20497798/taking-the-hog-descriptor-of-an-image-using-hogdescriptor-from-emgu-cv-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!