image-processing - 有人可以向我解释给定 github 链接中使用的“局部最大值”方法吗?
问题描述
我目前正在从事图像处理项目。我来看看这段从视频中提取关键帧的代码。但是我无法理解代码中使用的函数 smooth()。
def smooth(x, window_len=13, window='hanning'):
"""smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
(with the window size) in both ends so that transient parts are minimized
in the begining and end part of the output signal.
input:
x: the input signal
window_len: the dimension of the smoothing window
window: the type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'
flat window will produce a moving average smoothing.
output:
the smoothed signal
example:
import numpy as np
t = np.linspace(-2,2,0.1)
x = np.sin(t)+np.random.randn(len(t))*0.1
y = smooth(x)
see also:
numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve
scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string
"""
logger.info("length of frames: %d" % len(x))
# if x.ndim != 1:
# raise ValueError, "smooth only accepts 1 dimension arrays."
#
# if x.size < window_len:
# raise ValueError, "Input vector needs to be bigger than window size."
#
# if window_len < 3:
# return x
#
# if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
# raise ValueError, "Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"
s = np.r_[2 * x[0] - x[window_len:1:-1],
x, 2 * x[-1] - x[-1:-window_len:-1]]
#print(len(s))
if window == 'flat': # moving average
w = np.ones(window_len, 'd')
else:
w = getattr(np, window)(window_len)
y = np.convolve(w / w.sum(), s, mode='same')
return y[window_len - 1:-window_len + 1]
github页面的链接是:
https://github.com/abner-gong/video-keyframes-extraction-python-package/blob/master/KeyFrames.py
任何形式的帮助将不胜感激。谢谢。
解决方案
推荐阅读
- perl - 替换文本文件中的某些字符串会将剩余的文本移到下一行
- python - 在装饰器中访问 self 对象和装饰器参数
- javascript - 输入字段输入时的输入状态
- python - 在 Python 中计算列中日期之间时间间隔的简单方法
- typescript - 具有父子关系的 2 个实体的 GraphQL 突变返回第二个实体的旧值
- acumatica - 更新网格上所有行的字段
- c# - 从回测结果中寻找每日利润
- maven - 将带有分类器的工件发布到共享 pom 的 GitHub 包时,如何解决冲突?
- python - Python - 如果我不导入日志记录模块会发生日志记录
- mysql - AWS Data Pipeline - SQLActivity 到 S3 (MySQL DB)