使用phoron&PyQ与自定义图形叠加视频

2024-10-01 09:20:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用PyQt4和声子模块构建一个眼球跟踪数据可视化工具。基本上,我有一个视频,一个受试者正在观看,而被试者的眼球运动被跟踪。眼睛跟踪数据是以x,y坐标的形式。我希望能够播放感兴趣的视频,并用圆圈覆盖该视频,以指示被摄对象正在查看的位置。在

有人知道吗?根据这个链接:Play a video with custom overlay graphics 似乎有办法声子视频小工具在QGraphicsProxyWidget中,但我不确定实现建议的方法。在

任何帮助将不胜感激!在

我还想知道是否有方法使用pyqtgraph实现我想要的功能。在


Tags: 模块工具数据方法视频可视化感兴趣形式
1条回答
网友
1楼 · 发布于 2024-10-01 09:20:59

当您注释一个选项是使用qgraphicsproxy widget时,您可以创建该类型的对象,也可以使用addWidget:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.phonon import Phonon

class Widget(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)
        lay = QVBoxLayout(self)
        vp = Phonon.VideoPlayer()
        media = Phonon.MediaSource('/path/of/video')
        vp.load(media)
        vp.play()
        scene = QGraphicsScene()
        self.view = QGraphicsView(scene, self)
        lay.addWidget(self.view)
        proxy = scene.addWidget(vp)
        # or 
        # proxy = QGraphicsProxyWidget()
        # scene.addItem(proxy)
        self.item = scene.addEllipse(QRectF(0, 0, 20, 20), QPen(Qt.red), QBrush(Qt.green))
        self.item.setParentItem(proxy)

    def mousePressEvent(self, event):
        p = self.view.mapToScene(event.pos())
        # move item
        self.item.setPos(p-QPoint(20, 20))
        QWidget.mousePressEvent(self, event)

    def resizeEvent(self, event):
        if event.oldSize().isValid():
            print(self.view.scene().sceneRect())
            self.view.fitInView(self.view.scene().sceneRect(), Qt.KeepAspectRatio)
        QWidget.resizeEvent(self, event)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_())

输出:

enter image description here

相关问题 更多 >