【发布时间】:2022-01-05 08:31:22
【问题描述】:
我正在尝试按照this 论文实现欧拉视频放大,但是在使用巴特沃斯带通滤波器时,它不断遇到“ValueError: object of too small depth for desired array”
这是我的巴特沃斯带通滤波器代码:
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = scipy.signal.lfilter([b], [a], data, axis=0) #The line that errors
return y
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = scipy.signal.butter(order, [low, high], btype='band')
return b, a
我在以下代码行中使用了 butter_bandpass_filter:
magnify_motion(tired_me, 0.4, 3)
def magnify_motion(video, low, high, n=4, sigma=3, amp=20):
lap_video_lst = video.get_laplacian_lst(n=n, sigma=sigma)
print("lap_video_lst shapes:")
for i in range(n):
print("{}:".format(i), get_list_shape(lap_video_lst[i]))
ret_lst = []
for layer in range(n):
filtered_layer = butter_bandpass_filter(lap_video_lst[layer], low, high, video.fps) #This line
filtered_layer *= amp
ret_lst.append(filtered_layer)
return ret_lst
其中每个 lap_video_lst[layer] 被格式化为具有形状 (frame_count, height, width, colour_channels) 的视频所有帧的 numpy 数组,打印时如下:
0: (330, 360, 640, 3)
1: (330, 180, 320, 3)
2: (330, 90, 160, 3)
3: (330, 45, 80, 3)
请注意,每个“层”具有不同维度的原因是它们是原始视频的拉普拉斯金字塔。
如果有用的话,I 这是 b 和 np 数组的形状,以及它们各自的值。
b: (1, 11)
[[ 0.00069339 0. -0.00346694 0. 0.00693387 0.
-0.00693387 0. 0.00346694 0. -0.00069339]]
a: (1, 11)
[[ 1. -8.02213491 29.18702261 -63.4764537 91.44299881
-91.21397148 63.81766134 -30.92689236 9.93534351 -1.91057439
0.16700076]]
这是完整的错误跟踪,以防我忽略了一些细节:
Traceback (most recent call last):
File "d:\Desktop\Stuff\Uni notes B\2021 Fall\Cs194\Projects\Project Final 1\tester.py", line 84, in <module>
main()
File "d:\Desktop\Stuff\Uni notes B\2021 Fall\Cs194\Projects\Project Final 1\tester.py", line 71, in main
magnify_motion(tired_me, 0.4, 3)
File "d:\Desktop\Stuff\Uni notes B\2021 Fall\Cs194\Projects\Project Final 1\tester.py", line 32, in magnify_motion
filtered_layer = butter_bandpass_filter(lap_video_lst[layer], low, high, video.fps)
File "d:\Desktop\Stuff\Uni notes B\2021 Fall\Cs194\Projects\Project Final 1\tester.py", line 17, in butter_bandpass_filter
y = scipy.signal.lfilter([b], [a], data, axis=0)
File "C:\Users\nick-\AppData\Roaming\Python\Python38\site-packages\scipy\signal\signaltools.py", line 1972, in lfilter
raise ValueError('object of too small depth for desired array')
ValueError: object of too small depth for desired array
任何提示都会有所帮助!谢谢:D
更新: 我在“b”和“a”周围使用方括号的原因是因为没有它我会得到以下错误,我被告知我应该如何解决这个问题
ValueError: could not convert b, a, and x to a common type
【问题讨论】:
-
“这是我的巴特沃斯带通滤波器代码:...” 这看起来与我的旧代码(从 2012 年开始)相似:stackoverflow.com/questions/12093594/…。但是你为什么在
lfilter的调用中在b和a周围加上额外的括号? -
方括号是为了防止下面的Valueerror; "ValueError: could not convert b, a, and x to a common type" 不知道为什么会发生。
标签: python numpy scipy computer-vision valueerror