【问题标题】:Python Apply Low Pass Filter On Some DataPython对某些数据应用低通滤波器
【发布时间】:2019-06-19 23:52:53
【问题描述】:

我有一个 .txt 文件,其中包含视频的一些帧差。 该项目是使用这些帧差异和低通滤波器去除噪声并稳定视频。

Vibrated2.txt 文件是:

0.341486, -0.258215
0.121945, 1.27605
-0.0811261, 0.78985
-0.0269414, 1.59913
-0.103227, 0.518159
0.274445, 1.69945
, ...

如何对这些数据应用低通滤波器?

我试过了,但是没用!

import cv2
import numpy as np
from scipy.signal import butter, lfilter

video= cv2.VideoCapture('Vibrated2.avi')
freq = (video.get(cv2.CAP_PROP_FPS))
cutoff = 5

data = np.loadtxt('Vibrated2.txt', delimiter=',')

b, a = butter(5, (cutoff/freq), btype='low', analog=False)
data = lfilter(b, a, data)

有什么帮助吗?有什么想法吗?

【问题讨论】:

  • 发生了什么问题?
  • 目标是稳定视频。它对视频没有任何改变。我什至不知道我做的是否正确。我在这个链接中问了另一个详细的问题:stackoverflow.com/questions/54368246/…
  • 当您已经有了确切的帧差异时,为什么不能将每个图像移动该数量并填充它?

标签: python matlab numpy opencv scipy


【解决方案1】:

我不确定您的 txt 文件的结构,但如果您想在帧差分输出上应用低通滤波器,我猜您想将其设为二进制?

def icv_check_threshold(pixel_value, desired_minimum_value):
    if pixel_value < desired_minimum_value: 
        return False 
    else:
        return True

对于帧差:

def icv_pixel_frame_differencing(frame_1, frame_2):
#  first convert frames to numpy arrays to make it easier to work with
    first_frame = np.asarray(frame_1, dtype=np.float32)
    second_frame = np.asarray(frame_2, dtype=np.float32)

#  then compute frame dimensions
    frame_width = int(first_frame[0].size)
    frame_height = int(first_frame.size/frame_width)

#  we then create a stock image for differencing output
    frame_difference = np.zeros((frame_height, frame_width), np.uint8)

   for i in range(0, frame_width - 1):
        for j in range(0, frame_height - 1):
        # compute the absolute difference between the current frame and first frame
            frame_difference[j, i] = abs(first_frame[j, i] - second_frame[j, i])
        # check if the threshold = 25 is satisfied, if not set pixel value to 0, else to 255
        # comment out code below to obtain result without threshold / non-binary
            if icv_check_threshold(frame_difference[j, i]):
                frame_difference[j, i] = 255
            else:
                frame_difference[j, i] = 0

    cv2.imwrite("differenceC.jpg", frame_difference)
    cv2.imwrite("frame50.jpg", first_frame)
    cv2.imwrite("frame51.jpg", second_frame)
    return frame_difference

我希望这会有所帮助。这里还有a link 我正在研究的一个帧差分项目。

【讨论】:

    猜你喜欢
    • 2019-04-29
    • 2016-02-29
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 2011-05-29
    • 2015-05-09
    相关资源
    最近更新 更多