I have the following code where I am taking every pixel across multiple frames in a video and passing it through a low pass filter (essentially temporal filtering of every pixel values). I am then taking these filtered pixels and creating new frames in the buf2 array.
import cv2, numpy as np
from scipy.signal import butter, lfilter, freqz
from numba import jit
# Filter requirements.
order = 1
fs = 30.0 # sample rate, Hz
cutoff = 0.3 # desired cutoff frequency of the filter, Hz
buf2 = np.empty((frameCount, frameHeight, frameWidth, 3), np.dtype('uint8'))
for j in range(rows_in_frame):
for k in range(columns_in_frame):
l = array_containing_all_frames[:, j, k, 1] #Only looking at green channel
y = butter_lowpass_filter(l, cutoff, fs, order)
buf2[:, j, k, 1] = y
This takes a long time to run depending on the size of the frame and number of frames. I wanted to speed it up as much as possible so I have been trying to apply Numba to this problem in the following:
@jit(nopython=True)
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
However, it just returns an error saying TypingError: Failed in nopython mode pipeline (step: nopython frontend) Untyped global name 'lfilter': cannot determine Numba type of <class 'function'>
I wanted to know how I should use Numba properly in my situation to speed up the whole process as much as possible.