从 OpenCV 获取 HOG 图像特征 + Python?
我读过这篇关于如何使用 OpenCV 基于 HOG 的行人检测器的文章:如何使用 OpenCV 检测和跟踪人?
我想使用 HOG 检测图像中其他类型的物体(不仅仅是行人)。然而,HOGDetectMultiScale 的 Python 绑定似乎无法访问实际的 HOG 功能。
有没有办法使用Python + OpenCV直接从任何图像中提取HOG特征?
I've read this post about how to use OpenCV's HOG-based pedestrian detector: How can I detect and track people using OpenCV?
I want to use HOG for detecting other types of objects in images (not just pedestrians). However, the Python binding of HOGDetectMultiScale doesn't seem to give access to the actual HOG features.
Is there any way to use Python + OpenCV to extract the HOG features directly from any image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在 python opencv 中,你可以像这样计算 hog:
In python opencv you can compute hog like this:
1.获取内置文档: 在 Python 控制台上执行以下命令将帮助您了解 HOGDescriptor 类的结构:
2.示例代码: 这是使用不同参数初始化 cv2.HOGDescriptor 的代码片段(我在这里使用的术语是 OpenCV 文档中定义良好的标准术语 此处):
3。推理:生成的猪描述符的维度为:
9 个方向 X(获得 1 次标准化的 4 个角块 + 获得 2 次标准化的边缘上的 6x4 块 + 获得 4 次标准化的 6x6 块)= 1764。因为我只给出了 hog.compute() 的一个位置。
4.另一种初始化方法是从包含所有参数值的 xml 文件进行初始化:
要获取 xml 文件,可以执行以下操作:
并编辑 xml 文件中的相应参数值。
1. Get Inbuilt Documentation: Following command on your python console will help you know the structure of class HOGDescriptor:
2. Example Code: Here is a snippet of code to initialize an cv2.HOGDescriptor with different parameters (The terms I used here are standard terms which are well defined in OpenCV documentation here):
3. Reasoning: The resultant hog descriptor will have dimension as:
9 orientations X (4 corner blocks that get 1 normalization + 6x4 blocks on the edges that get 2 normalizations + 6x6 blocks that get 4 normalizations) = 1764. as I have given only one location for hog.compute().
4. One more way to initialize is from xml file which contains all parameter values:
To get an xml file one can do following:
and edit the respective parameter values in xml file.
这是一个仅使用 OpenCV 的解决方案:
我使用了 HOG 描述符计算和可视化 了解数据布局并对组上的循环进行矢量化。
Here is a solution that uses only OpenCV:
I have used HOG descriptor computation and visualization to understand the data layout and vectorized the loops over groups.
尽管事实上存在一种方法,如前面的答案中所述:
我想发布一个Python实现,你可以在opencv的示例目录中找到,希望它对理解HOG功能有用:
问候。
Despite the fact that exist a method as said in previous answers:
I would like to post a python implementation you can find on opencv's examples directory, hoping it can be useful to understand HOG funcionallity:
Regards.
我不同意peakxu的论点。 HOG 探测器最终“只是”一个刚性线性滤波器。 “物体”(即人)的任何自由度都会导致检测器模糊,并且实际上不会被检测器处理。该检测器使用潜在 SVM 进行了扩展,通过在独立部分(即头部、手臂等)之间引入结构约束以及允许每个对象(即正面人物和侧面人物)出现多种外观来明确处理自由度。 .)。
关于opencv中的HOG检测器:理论上你可以上传另一个检测器来与这些功能一起使用,但你不能获取这些功能本身。因此,如果您有经过训练的检测器(即特定类别的线性滤波器),您应该能够将其上传到检测器中以获得 opencv 的快速检测性能。也就是说,应该很容易破解 opencv 源代码以提供此访问权限并将此补丁反馈给维护人员。
I would disagree with the argument of peakxu. The HOG detector in the end is "just" a rigid linear filter. any degrees of freedom in the "object" (i.e. persons) lead to bluring in the detector, and are not actually handled by it. There is an extension of this detector using latent SVMs that does explicitly handle dgrees of freedom by introducing structural constraints between independent parts (i.e. head, arms, etc) as well as allowing for multiple appearances per object (i.e. frontal people and sideways people...).
Regarding the HOG detector in opencv: In theory you can upload another detector to be used with the features, but you cannot afaik get the features themselves. thus, if you have a trained detector (i.e. a class specific linear filter) you should be able to upload that into the detector to get the fast detections performance of opencv. that said it should be easy to hack the opencv source code to provide this access and propose this patch back to the maintainers.
我不建议使用 HOG 特征来检测行人以外的物体。在 Dalal 和 Triggs 最初的 HOG 论文中,他们特别提到他们的检测器是围绕行人检测构建的,允许四肢具有很大的自由度,同时使用人体周围的强烈结构提示。
相反,请尝试查看 OpenCV 的 HaarDetectObjects。您可以在此处了解如何训练自己的级联。
I would not recommend using HOG features for detecting objects other than pedestrians. In the original HOG paper by Dalal and Triggs, they specifically mentioned that their detector is built around pedestrian detection in allowing for significant degrees of freedom in the limbs while using strong structural hints around human body.
Instead, try looking at OpenCV's HaarDetectObjects. You can learn how to train your own cascades here.