类型错误scipy.signal.sepfir2d

2024-10-02 16:29:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图计算光流的导数(参考文献in my previous SO question),在执行计算时遇到了一个类型错误。在

我首先阅读了OpenCV中的视频,并使用它的光流方法来计算速度。然后我用化学信号库对速度运行高斯滤波器并计算导数。在

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时,我收到以下错误:

^{pr2}$

documentation on the Scipy website非常稀疏,我也找不到其他使用它的例子。sepfir2d的三个参数都是numpy数组;velx是一个矩阵,gxFilt和gFilt都是相同长度的向量(我想在本例中是5个)。你知道为什么会出现这种类型的错误吗?


Tags: andthe类型错误npframe导数光流
1条回答
网友
1楼 · 发布于 2024-10-02 16:29:55

经过大量测试(查看sepfir2d的源代码一点也没有帮助),结果发现问题在于我的velx和{}使用的是32位浮点原语,而它们需要是64位的。那就修好了。在

相关问题 更多 >