OpenCV HOGDescripter Python [英] OpenCV HOGDescripter Python
问题描述
我想知道是否有人知道为什么在OpenCV的Python绑定中没有HOGDescriptors的文档。
I was wondering if anyone knew why there is no documentation for HOGDescriptors in the Python bindings of OpenCV.
也许我只是错过了它们,但唯一的代码我发现它们就是这个主题:从OpenCV + Python获取HOG图像功能?
Maybe I've just missed them, but the only code I've found of them is this thread: Get HOG image features from OpenCV + Python?
如果您在该主题中向下滚动,则可在此处找到此代码:
If you scroll down in that thread, this code is found in there:
import cv2
hog = cv2.HOGDescriptor()
im = cv2.imread(sample)
h = hog.compute(im)
我已经测试了这个并且它有效 - 所以Python Bindings确实存在,只是文档没有。我想知道是否有人知道为什么HOG的Python绑定的文档很难找到/不存在。有谁知道是否有一个我可以在任何地方阅读HOG的教程(特别是通过Python绑定)?我是HOG的新手,想在我开始编写自己的东西之前看一些OpenCV如何处理的例子。
I've tested this and it works -- so the Python Bindings do exist, just the documentation doesn't. I was wondering if anyone knew why documentation for the Python bindings for HOG is so difficult to find / non-existent. Does anyone know if there is a tutorial I can read anywhere about HOG (especially via the Python Bindings)? I'm new to HOG and would like to see a few examples of how OpenCV does stuff before I start writing my own stuff.
推荐答案
的 1。获取内置文档:
python控制台上的以下命令将帮助您了解类HOGDescriptor的结构:
1. Get Inbuilt Documentation: Following command on your python console will help you know the structure of class HOGDescriptor:
import cv2
help(cv2.HOGDescriptor())
2。示例代码:
下面是一段代码,用于初始化具有不同参数的cv2.HOGDescriptor(我在这里使用的术语是在OpenCV文档中明确定义的标准术语这里):
import cv2
image = cv2.imread("test.jpg",0)
winSize = (64,64)
blockSize = (16,16)
blockStride = (8,8)
cellSize = (8,8)
nbins = 9
derivAperture = 1
winSigma = 4.
histogramNormType = 0
L2HysThreshold = 2.0000000000000001e-01
gammaCorrection = 0
nlevels = 64
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,
histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
#compute(img[, winStride[, padding[, locations]]]) -> descriptors
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)
hist = hog.compute(image,winStride,padding,locations)
3。推理:
结果hog描述符的维度为:
9个方向X(获得1个归一化的4个角块+获得2个归一化的边缘上的6x4块+获得4个的6x6块) normalizations)= 1764.因为我只为hog.compute()提供了一个位置。
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。初始化HOGDescriptor的不同方法:
初始化的另一种方法是从xml文件中包含所有参数值:
4. Different way to initialize HOGDescriptor:
One more way to initialize is from xml file which contains all parameter values:
hog = cv2.HOGDescriptor("hog.xml")
要获得xml文件可以执行以下操作:
To get an xml file one can do following:
hog = cv2.HOGDescriptor()
hog.save("hog.xml")
并编辑xml文件中的相应参数值。
and edit the respective parameter values in xml file.
这篇关于OpenCV HOGDescripter Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!