简体   繁体   English

为什么opencv的HOG描述符返回了这么多的值

[英]Why does opencv's HOG descriptor return so many values

I'm trying to use OpenCV's HOG descriptor, but the feature vector computed from it seems far too long. 我正在尝试使用OpenCV的HOG描述符,但是从它计算的特征向量似乎太长了。 Here is a snippet that demonstrates the problem: 这是一个演示问题的片段:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <stdlib.h>
#include <vector>

int main()
{
    cv::Mat image = cv::imread("1.jpg");
    std::vector<float> features;
    cv::HOGDescriptor hogdis;
    hogdis.compute(image, features);
    printf("HOG feature's length is %zu %zu\n", hogdis.getDescriptorSize(), features.size());
    return 0;
}

The output is 输出是

HOG feature's length is 3780 1606500

The latter value seems absurd. 后一个价值似乎很荒谬。 The image 1.jpg has dimension 256x256x3, which has much less pixels than the feature vector. 图像1.jpg尺寸为256x256x3,其像素比特征向量少得多。 Why does OpenCV fills the feature vector with so many values? 为什么OpenCV用如此多的值填充特征向量? How do I obtain the 3780 long vector to feed to my SVM trainer? 如何获取3780长矢量以供给我的SVM培训师?

Why does OpenCV fills the feature vector with so many values? 为什么OpenCV用如此多的值填充特征向量?

The size of hog features is determined by the following equation (not solely determined on the image dimensions): 猪特征的大小由以下等式确定(不仅仅根据图像尺寸确定):

size_hog_features = (size_t)nbins * ( blockSize.width/cellSize.width) 
                         * (blockSize.height/cellSize.height) * ((winSize.width 
                         - blockSize.width)/blockStride.width + 1) 
                         * ((winSize.height - blockSize.height)
                         / blockStride.height + 1);

So it's quite normal you got such a long HOG feature vector. 所以你有这么长的HOG特征向量是很正常的。

How do I obtain the 3780 long vector to feed to my SVM trainer? 如何获取3780长矢量以供给我的SVM培训师?

You can setup the parameters (ie nbins, blockSize, cellSize, winSize ) of HOG feature before computing it, in order to get a HOG feature with the size you want. 您可以在计算之前设置HOG功能的参数(即nbins, blockSize, cellSize, winSize ),以获得具有所需大小的HOG功能。

But why are hogdis.getDescriptorSize() and features.size() inconsistent? 但是为什么hogdis.getDescriptorSize()和features.size()不一致?

They are different. 它们是不同的。 getDescriptorSize() returns the number of coefficients required for the classification. getDescriptorSize()返回分类所需的系数数。 And it can be computed as follows (refer to here ): 它可以按如下方式计算(参见此处 ):

HOG descriptor length = #Blocks * #CellsPerBlock * #BinsPerCell

On the other hand, features.size() returns all the HOG feature size of the whole image. 另一方面, features.size()返回整个图像的所有HOG特征尺寸。

To train, you need to pass in features . 要训​​练,你需要传递features

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM