1

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
hectorcho
  • 13
  • 4
  • Check my answer and if it worked, do not forget to mark it as correct, if you do not know how to do it, check the following link: [tour] – eyllanesc Dec 04 '17 at 08:13

1 Answers1

0

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:

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Wow, thank you so much for helping me with the implementation! :) However, when I run this widget with my video, it does not play the video too nicely. Here is the output: [link](https://ibb.co/gAFFEb). And so I thought I would try the second method in your code: proxy = QGraphicsProxyWidget() scene.addItem(proxy) but this just gives me a blank canvas with no video playing in the background. [link](https://ibb.co/guzNSw) Any idea on how to solve these issues? Thank you so much! – hectorcho Dec 04 '17 at 14:48
  • @Hector What extension does your video have? – eyllanesc Dec 04 '17 at 14:50
  • @Hector You can share the video – eyllanesc Dec 04 '17 at 14:50
  • My video is an mp4. – hectorcho Dec 04 '17 at 14:52
  • @Hector Try installing the following: `sudo apt install phonon4qt5 phonon4qt5-backend-gstreamer phonon4qt5-backend-vlc` – eyllanesc Dec 04 '17 at 14:54
  • @Hector I could help you through teamviewer – eyllanesc Dec 04 '17 at 14:57
  • That would be awesome. How can we go about doing that? – hectorcho Dec 04 '17 at 15:01
  • @Hector Install teamviewer following the steps below: https://community.teamviewer.com/t5/Knowledge-Base/Installation-of-TeamViewer-on-a-Ubuntu-system/ta-p/45 – eyllanesc Dec 04 '17 at 15:04