【发布时间】:2011-12-19 14:12:37
【问题描述】:
我正在尝试计算光流的导数(参考 in my previous SO question)并且在执行计算时遇到了 TypeError。
我首先阅读了使用 OpenCV 的视频,并使用其光流方法来查找速度。然后我使用 scipy.signal 库对速度运行高斯滤波器并计算导数。
cv.CalcOpticalFlowLK(prev_frame, curr_frame, (11, 11), velx, vely)
# ... convert velx and vely to numpy arrays ...
# Set up the gaussian filter and its derivative.
sigmaBlur = 1
sigmaGrey = 4
gBlurSize = 2 * np.around(2.5 * sigmaBlur) + 1
x = np.mgrid[1:gBlurSize + 1] - np.around((gBlurSize + 1) / 2)
gFilt = np.exp(-(x ** 2) / (2 * (sigmaBlur ** 2)))
gFilt /= np.sum(gFilt)
gxFilt = (-x / (sigmaBlur ** 2)) * gFilt
# Now calculate the derivative of the velocity.
res = scipy.signal.sepfir2d(velx, gxFilt, gFilt)
# ... 3 more calls to sepfir2d ... #
不幸的是,在调用 sepfir2d 时,我收到以下错误:
TypeError: array cannot be safely cast to required type
documentation on the Scipy website 非常稀少,我找不到很多其他使用它的例子。 sepfir2d 的所有三个参数都是 numpy 数组; velx 是一个矩阵,而 gxFilt 和 gFilt 都是相同长度的向量(我认为在这种情况下为 5)。 任何想法为什么会发生类型错误?
【问题讨论】:
-
对于它的价值
scipy.signal.seqfir2d似乎是一种相当奇怪的方式来做到这一点......任何原因你不能使用更常见的路线之一,例如scipy.ndimage.gaussian_gradient_magnitude等? -
我实际上是在辩论使用它,但我无法仅从文档中判断它是否是我需要的。它和我上面写的代码做同样的事情吗? (我对光流领域还很陌生,所以在解释时可以随意详细说明)
标签: python image-processing opencv scipy opticalflow