OpenCV Python 和定向梯度直方图
有没有关于在 Python OpenCV 中使用 HOGDescriptor 功能的有用文档?我已经阅读了 C++ 文档,但 Python 版本的功能不同,我无法仅通过修补来弄清楚。
最具体地说,我正在Python中寻找一个OpenCV命令,该命令将图像和像素位置作为输入(可能还有一些关于检测窗口大小的参数),然后只返回一个包含HOG特征向量的Python数组(即列表或 NumPy 数组等,其中列表的第 j 个元素是定向梯度直方图中的第 j 个直方图分量)。
我的目标是将这些直方图输入 scikits.learn SVM 管道(这样我就可以避免 OpenCV SVM 训练),但要做到这一点,我需要实际的特征向量本身,而不是 OpenCV 似乎需要的那种 HOG 处理链管道使用。
HOG 代码的任何其他 Python 实现也可以工作。我需要一些相当有效的东西来与我自己编写的另一个代码库进行比较。
Is there any useful documentation for using the HOGDescriptor functionality in Python OpenCV? I have read the C++ documentation, but the Python version functions differently and I cannot figure it out just by tinkering.
Most specifically, I am seeking an OpenCV command in Python that takes an image and a pixel location as input (and possibly also some parameters about the size of a detection window) and then just returns a Python array that contains the HOG feature vector (i.e. a list or NumPy array, etc., where the jth element of the list is the jth histogram component from a histogram of oriented gradients).
My goal is to feed these histograms into the scikits.learn SVM pipelines (so I can avoid the OpenCV SVM training), but to do this I need the actual feature vectors themselves and not the sort of HOG processing chain pipelines stuff that OpenCV appears to use.
Any other Python implementations of HOG code would work too. I need something reasonably efficient though to compare with another code base that I am writing myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有点晚了,但是,为了将来的参考, scikit-image 有一个 HOG。这是一个可以提取给定图像的定向梯度直方图的单个函数。
This is a little late, but, for future reference, scikit-image has an implementation of HOG. This is a single function that could extract the Histogram of Oriented Gradients for a given image.
怎么样 Matlab作为灵感,属于这个文章
How about a bit of Matlab as inspiration, belonging to this article
看看http://sourceforge.net/projects/hogtrainingtuto/?_test=beta 一些 HOG python 代码和一堆 C、cpp、java 实现。至于python和opencv的真实文档,我也很茫然。但这应该对你有一点帮助
take a look at http://sourceforge.net/projects/hogtrainingtuto/?_test=beta for some HOG python code and a bunch of C, cpp, java implementations. As for real documentations of python and opencv, I too am at a loss. But this should help you a bit
'Poselets' 实现这里有一个 HOG 描述符的 C 实现,尽管写成考虑到 matlab,可以调整为使用 ctypes 和 numpy 与 python 一起运行。
您可以删除所有 mex 例程,并在 C 函数中将输入和输出数组声明为
float *
。您确实需要确保您的 numpy 数组是 Fortran 连续的。这可以通过以下方式实现:
image = image.copy(order='F', dtype = float32)
The 'Poselets' implementation here has a C implementation of HOG descriptors which, although written with matlab in mind, can be adapted to run with python using ctypes and numpy.
You can remove all the mex routines, and declare your input and output arrays as
float *
in the C function.You do need to make sure that your numpy arrays are Fortran contiguous. This can be achieved by:
image = image.copy(order='F', dtype = float32)