[英]OpenCV+Python+HOG proper location argument for “compute” function
我正在运行OpenCV 2.4.6和Python 2.7,我刚接触Python编程。
我需要在我的Python脚本中调用HoGDescriptor类的“计算”功能。
其中一个参数是计算(并返回)hog描述符的位置。
在c ++中,这个参数是vector&type。 但是,在Python中,我尝试了一些阵列或垫子组合,但它没有用。
我复制下面的代码(这很简单)。
import numpy as np
import cv2
# read INRIAPerson sample
i = cv2.imread('crop_000023a.png',0)
hog = cv2.HOGDescriptor()
# let say I want to caculate hog descriptors in the roi
# being at (2,3) position of the image
r=[1,2]
descriptors = hog.compute(i,hog.blockStride,hog.cellSize,r)
我得到了这个错误
TypeError Traceback(最近一次调用最后一次)
in()
----> 1个描述符= hog.compute(i,hog.blockStride,hog.cellSize,r)
TypeError:locations
如果我做了类似的东西
r=mat([1,2]) or r=array([1,2]) or r=array([1,2],ndmin=2)
它崩溃了。
有没有人知道如何在Python中将正确的参数传递给这个函数?
提前致谢,
巴勃罗·内格里
您是否有可能尝试计算过于接近图像边界的描述符? 尝试将r
设置为距图像边界至少8像素的位置。
首先,让我们检查一下hog.compute
是否有一些文档:
>> print hog.compute.__doc__
这使:
compute(img[, winStride[, padding[, locations]]]) -> descriptors
嗯,也许我们应该将locations
设置为简单的元组元组? 让我们试一试:
r = ((100, 200), ) # for now let's stay away from the boundaries
descriptors = hog.compute(i, hog.blockStride, hog.cellSize, r)
print descriptors.shape
我们肯定得到:
(3780, 1)
瞧! 问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.