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

Siy*_*Ren 10 c++ opencv computer-vision

我正在尝试使用OpenCV的HOG描述符,但是从它计算的特征向量似乎太长了.这是一个演示问题的片段:

#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;
}
Run Code Online (Sandbox Code Playgroud)

输出是

HOG feature's length is 3780 1606500
Run Code Online (Sandbox Code Playgroud)

后一个价值似乎很荒谬.图像的1.jpg尺寸为256x256x3,其像素比特征向量少得多.为什么OpenCV用如此多的值填充特征向量?如何获取3780长矢量以供给我的SVM培训师?

her*_*tao 17

为什么OpenCV用如此多的值填充特征向量?

猪特征的大小由以下等式确定(不仅仅根据图像尺寸确定):

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);
Run Code Online (Sandbox Code Playgroud)

所以你有这么长的HOG特征向量是很正常的.

如何获取3780长矢量以供给我的SVM培训师?

您可以nbins, blockSize, cellSize, winSize在计算之前设置HOG功能的参数(即),以获得具有所需大小的HOG功能.

但是为什么hogdis.getDescriptorSize()和features.size()不一致?

它们是不同的.getDescriptorSize()返回分类所需的系数数.它可以按如下方式计算(参见此处):

HOG descriptor length = #Blocks * #CellsPerBlock * #BinsPerCell
Run Code Online (Sandbox Code Playgroud)

另一方面,features.size()返回整个图像的所有HOG特征尺寸.

要训​​练,你需要传球features.