使用 Phonon 和 PyQt 用自定义图形覆盖视频

Overlay video with custom graphics using Phonon & PyQt

我正在使用 PyQt4 和 Phonon 模块构建眼动数据可视化工具。本质上,我有一段视频,该视频记录了一个对象在跟踪其眼球运动时正在观看的视频。眼动追踪数据采用 x,y 坐标的形式。我希望能够播放感兴趣的视频并用圆圈覆盖该视频,指示对象正在看的位置。

有人知道吗?根据这个link:Play a video with custom overlay graphics 似乎有一种方法可以将 Phonon.VideoWidget 放在 QGraphicsProxyWidget 中,但我不确定实现该建议的方法。

如有任何帮助,我们将不胜感激!

我也很想知道是否有办法使用 pyqtgraph 实现我想要的功能。

正如您评论的选项是使用 QGraphicsProxyWidget,您可以创建该类型的对象或使用 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_())

输出: