使用Phonon& amp;将视频与自定义图形叠加PyQt [英] Overlay video with custom graphics using Phonon & PyQt

查看:135
本文介绍了使用Phonon& amp;将视频与自定义图形叠加PyQt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PyQt4和Phonon模块构建眼动数据可视化工具.本质上,我有一个视频,当跟踪对象的眼动时,该对象正在观看.眼睛跟踪数据采用x,y坐标的形式.我希望能够播放感兴趣的视频,并用圆圈将其覆盖,以指示对象正在看的地方.

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.

有人有什么主意吗?根据此链接:播放具有自定义叠加层图形的视频 将Phonon.VideoWidget放在QGraphicsProxyWidget内似乎是一种方法,但我不确定实现该建议的方法.

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.

任何帮助将不胜感激!

我也很想知道是否有使用pyqtgraph实现所需功能的方法.

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

推荐答案

在您评论使用QGraphicsProxyWidget的选项时,您可以创建该类型的对象,也可以使用addWidget:

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_())

输出:

这篇关于使用Phonon& amp;将视频与自定义图形叠加PyQt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆