OpenCV 中的 HOG 用于对整个图像进行分类
据我所知,OpenCV 中的梯度直方图通常用于图像块,以便检测和分类图像中的对象。
但是,我想使用 HOG 构建可用于对整个图像进行分类的特征向量。使用以下内容:
std::vector<float> temp_FV_out;
cv::HOGDescriptor hog;
hog.compute(img_in, temp_FV_out);
由于图像大小不同,给出非常长的特征向量,每个特征向量的长度不同 - 较大的图像具有更多的 64 x 128 窗口,并且每个特征向量都会影响特征向量的长度。
如何让 OpenCV 从每个图像中给出一个短特征向量(大约 5-20 个 bin),其中无论图像大小如何,特征向量的长度都保持不变?我宁愿不使用词袋来构建 HOG“单词”词典。
I understand that Histograms of Gradients in OpenCV are typically used on image patches in order to detect and classify objects in an image.
However, I would like to use HOG to build a feature vector that can be used to classify an entire image. Using the following:
std::vector<float> temp_FV_out;
cv::HOGDescriptor hog;
hog.compute(img_in, temp_FV_out);
gives very long feature vectors each of different lengths, due to the varying size of the image - larger images have more 64 x 128 windows, and each of these contributes to the feature vector's length.
How can I get OpenCV to give a short feature vector (about 5-20 bins) from each image, where the length of the feature vector remains constant regardless of the image's size? I would rather not use bag of words to build a dictionary of HOG 'words'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一步是标准化图像尺寸 - 选择要处理的最小尺寸,并将其余尺寸调整为该基本尺寸。您还可以设置一个小尺寸作为默认值(例如 100x100),如果它们没有相同的宽高比,您可能需要裁剪它们。
接下来,您可以根据各种算法从向量中选择许多特征:PCA、决策树、Ada boost 等 - 这可以帮助您从数据中提取最重要的值。
First step is to normalize the image size - choose the smallest size you want to process,and resize the rest to this base size. You can also establish a small size as default (100x100, by example) You may need to crop them, if they do not have the same aspect ratio.
Next, you can select a number of features from your vector, based on various algorithms: PCA, decision trees, Ada boost, etc - which can help you extract the most significant values from your data.