1
我試圖從圖像中提取HOG描述符,但總是得到零作爲結果。它如何解決。這裏是我用來提取HOG描述符的C#代碼。EmguCV HOG描述符始終爲零
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);
}
謝謝。代碼在項目屬性中啓用「本地代碼調試」後工作。 –