import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import numpy as np
import cv2
WIN_W = 1000
WIN_H = 600
SIGMA = 10
x = 0
y = 0
class OneEuroFilter:
def __init__(self, te, mincutoff=1.0, beta=0.007, dcutoff=1.0):
self.x = None
self.dx = 0
self.te = te
self.mincutoff = mincutoff
self.beta = beta
self.dcutoff = dcutoff
self.alpha = self._alpha(self.mincutoff)
self.dalpha = self._alpha(self.dcutoff)
def _alpha(self, cutoff):
tau = 1.0 / (2 * np.pi * cutoff)
return 1.0 / (1.0 + tau / self.te)
def predict(self, x, te):
result = x
if self.x is not None:
edx = (x - self.x) / te
self.dx = self.dx + (self.dalpha * (edx - self.dx))
cutoff = self.mincutoff + self.beta * abs(self.dx)
self.alpha = self._alpha(cutoff)
result = self.x + self.alpha * (x - self.x)
self.x = result
return result
class MainThread(QThread):
def __init__(self, canvas):
super(MainThread, self).__init__()
self.canvas = canvas
self.t1 = time.perf_counter()
self.te = 0.04 # time elapsed per frame
self.filter_x = OneEuroFilter(self.te)
self.filter_y = OneEuroFilter(self.te)
def update_fps(self):
t2 = time.perf_counter()
self.te = t2 - self.t1
self.t1 = t2
def run(self):
while True:
global x, y
noise_x = x + np.random.normal(0, SIGMA)
noise_y = y + np.random.normal(0, SIGMA)
predict_x = self.filter_x.predict(noise_x, self.te)
predict_y = self.filter_y.predict(noise_y, self.te)
img = np.ones((WIN_H, WIN_W, 3), dtype=np.uint8) * 255
cv2.circle(img, (int(noise_x), int(noise_y)), 5, (0, 0, 0), -1)
cv2.circle(img, (int(predict_x), int(predict_y)), 5, (0, 0, 255), -1)
cv2.putText(img, "Te: {:.4f}s".format(self.te), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
cv2.putText(img, "Black: Noise", (10, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
cv2.putText(img, "Red: Filtered", (10, 110), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
self.canvas.setPixmap(QPixmap.fromImage(QImage(img.data, img.shape[1], img.shape[0], img.shape[1] * 3, QImage.Format_RGB888)))
time.sleep(0.03)
self.update_fps()
class Canvas(QLabel):
def __init__(self, parent=None):
super(Canvas, self).__init__(parent)
self.setFixedSize(WIN_W, WIN_H)
self.setMouseTracking(True)
self.setStyleSheet("background-color: white;")
self.main_thread = MainThread(self)
self.main_thread.start()
def mouseMoveEvent(self, event):
global x, y
x = event.x()
y = event.y()
class MainWidget(QWidget):
def __init__(self, parent=None):
super(MainWidget, self).__init__(parent)
self.initUI()
def initUI(self):
self.setWindowTitle("One Euro Filter")
self.resize(WIN_W, WIN_H)
self.canvas = Canvas(self)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWidget = MainWidget()
sys.exit(app.exec_())
没有合适的资源?快使用搜索试试~ 我知道了~
Python 一欧元滤波器 OneEuroFilter PyQt可视化跟随鼠标
共2个文件
py:1个
mp4:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 193 浏览量
2022-10-19
16:28:24
上传
评论
收藏 331KB ZIP 举报
温馨提示
# Python 一欧元滤波器 OneEuroFilter PyQt可视化跟随鼠标 1. 使用PyQt制作可视化界面; 2. 获取鼠标在窗口中当前位置,加入高斯噪声; 3. 将加入噪声的鼠标坐标作为输入,进行一欧元滤波; 4. 可以看到效果十分跟手,这是该滤波的特点
资源详情
资源评论
资源推荐
收起资源包目录
Python 一欧元滤波器 OneEuroFilter PyQt可视化跟随鼠标.zip (2个子文件)
oneeurofilter
示例视频.mp4 2.81MB
oneeurofilter.py 3KB
共 2 条
- 1
两只程序猿
- 粉丝: 350
- 资源: 158
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- densenet模型-python语言pytorch框架的图像分类宠物行为分类识别-不含数据集图片-含逐行注释和说明文档.zip
- alexnet模型-基于深度学习识别水果种类-不含数据集图片-含逐行注释和说明文档.zip
- earsertrweeqewrr
- alexnet模型-基于深度学习对草莓品级果识别-不含数据集图片-含逐行注释和说明文档.zip
- 微信小程序五子棋游戏,有悔棋,清屏等功能
- alexnet模型-python语言pytorch框架训练识别餐桌美食-不含数据集图片-含逐行注释和说明文档.zip
- proteus下载安装 具体步骤
- proteus下载安装 具体步骤
- proteus下载安装 具体步骤
- proteus下载安装 具体步骤
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0