From 64250e8f150665dd21a03ff7f497d44b4e942217 Mon Sep 17 00:00:00 2001 From: NSQY <34185288+NSQY@users.noreply.github.com> Date: Sun, 22 Dec 2024 13:59:19 +1030 Subject: [PATCH] use fftspectrum-rs and drop opencv (#16) * update freq_dft_view to use fftspectrum-rs * remove opencv from requirements.txt * fix typo * Delete dft-view/requirements.txt --------- Co-authored-by: emotion3459 <176516814+emotion3459@users.noreply.github.com> --- dft-view/freq_dft_view.ppy | 26 ++++++++++++-------------- dft-view/requirements.txt | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) delete mode 100644 dft-view/requirements.txt diff --git a/dft-view/freq_dft_view.ppy b/dft-view/freq_dft_view.ppy index 6befe5d..a67321e 100644 --- a/dft-view/freq_dft_view.ppy +++ b/dft-view/freq_dft_view.ppy @@ -10,27 +10,25 @@ __all__ = [ class DFTViewPlugin(MappedNodesViewPlugin): _config = PluginConfig('dev.setsugen.fft_view', 'DFT View') + _url = 'https://github.com/sgt0/vapoursynth-fftspectrum-rs' def get_node(self, node: vs.VideoNode) -> vs.VideoNode: - import numpy as np - from cv2 import DFT_COMPLEX_OUTPUT, dft # type: ignore + if not hasattr(vs.core, 'fftspectrum_rs'): + raise AttributeError( + 'The required plugin "fftspectrum_rs" is not installed. ' + f'Please install it from: {self._url}' + ) + planes = split(depth(node, 32)) - def _to_polar(f: vs.VideoFrame, n: int) -> vs.VideoFrame: - src = np.asarray(f[0]) - dft_shift = np.fft.fftshift(dft(src, flags=DFT_COMPLEX_OUTPUT)) - mag = np.sqrt(np.power(dft_shift[:, :, 1], 2), np.power(dft_shift[:, :, 0], 2)) - dst = f.copy() - np.copyto(np.asarray(dst[0]), np.log(mag) / 10) - return dst - if len(planes) == 1: - y = planes[0] - - return y.std.ModifyFrame(y, _to_polar) + return planes[0].fftspectrum_rs.FFTSpectrum() - planes = [c.std.ModifyFrame(c, _to_polar).text.Text(text=k) for k, c in zip(node.format.name, planes)] + planes = [ + c.fftspectrum_rs.FFTSpectrum().text.Text(text=k) + for k, c in zip(node.format.name, planes) + ] subsampling = node.format.subsampling_w, node.format.subsampling_h diff --git a/dft-view/requirements.txt b/dft-view/requirements.txt deleted file mode 100644 index b29fe46..0000000 --- a/dft-view/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -opencv-python>=4.7.0.72 \ No newline at end of file