Overlay video with custom graphics using Phonon & PyQt

大城市里の小女人 提交于 2020-04-17 16:47:37

问题


I am building a eye-tracking data visualization tool using PyQt4 and Phonon module. Essentially, I have a video that a subject was watching while the subject's eye movements were tracked. The eye tracking data is in the form of x,y coordinates. I want to be able to play the video of interest and overlay that video with circles indicating where the subject was looking at.

Does anyone have any idea? According to this link: Play a video with custom overlay graphics there seems to be a way by placing Phonon.VideoWidget inside a QGraphicsProxyWidget but I am unsure of a method to implement the suggestion.

Any help would be greatly appreciated!

I am also interested to know if there are ways to achieve my desired functionaility using pyqtgraph.


回答1:


As you comment an option is to use QGraphicsProxyWidget, you can create an object of that type or you can use 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_())

Output:



来源:https://stackoverflow.com/questions/47627879/overlay-video-with-custom-graphics-using-phonon-pyqt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!