Как воспроизвести видео с камеры в PyQt4?

На самом деле я работаю над RasPberry Pi 3, для которого я сделал графический интерфейс с использованием PyQt4, и я хочу воспроизводить живой поток видео, которое я снимаю с камеры в GUI. Я знаю, что видео воспроизводится в PyQt4 с использованием phonon..... но я не знаю, как я могу транслировать на него прямой эфир.

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

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.setGeometry(10,10,320,240)

        self.first_box  = QtGui.QVBoxLayout()
        self.second_box = QtGui.QVBoxLayout()
        self.third_box  = QtGui.QVBoxLayout()

        #self.zvbox = QtGui.QVBoxLayout()

        vbox = QtGui.QVBoxLayout()
        vbox.addLayout(self.first_box)
        vbox.addLayout(self.second_box)
        vbox.addLayout(self.third_box)
        self.setLayout(vbox)

        self.first_view()

        #self.resize(100, 200)
        #self.center()

        self.setWindowTitle('Trying Final')

    def keyPressEvent(self, event):
        if event.key() == QtCore.Qt.Key_Escape:
            self.close()

    def first_view(self):

        powerButton = QtGui.QPushButton("Power")
        settingButton = QtGui.QPushButton("Settings")
        videoButton = QtGui.QPushButton("Video")
        savedfileButton = QtGui.QPushButton("Saved Records")
        newButton = QtGui.QPushButton("New Record")

        powerButton.clicked.connect(self.first_second_view)
        settingButton.clicked.connect(self.first_third_view)
        videoButton.clicked.connect(self.first_fourth_view)
        savedfileButton.clicked.connect(self.first_fifth_view)
        newButton.clicked.connect(self.first_sixth_view)


        hbox = QtGui.QHBoxLayout()
        #hbox.addStretch(1)
        hbox.addWidget(newButton)
        hbox.addWidget(savedfileButton)
        hbox.addWidget(videoButton)
        hbox.addWidget(settingButton)
        hbox.addWidget(powerButton)

        #vbox = QtGui.QVBoxLayout()
        font = QtGui.QFont()
        font.setBold(True)
        font.setPixelSize(12)
        lbl1 = QtGui.QLabel('Select an option', self)
        lbl1.setFont(font)
        lbl2 = QtGui.QLabel('Welcome to the Pupilometer', self)
        lbl2.setFont(font)
        self.first_box.addWidget(lbl1)
        self.second_box.addWidget(lbl2)
        #self.second_box.addStretch(1)
        self.third_box.addLayout(hbox)

    def first_second_view(self):
        print "first_second_view"
        #self.remove_view()
        self.clearLayout(self.second_box)
        self.second_view()

    def second_view(self):
        font = QtGui.QFont()
        font.setBold(True)
        font.setPixelSize(12)
        lbl1 = QtGui.QLabel('Power Off?', self)
        lbl1.setFont(font)
        yesButton = QtGui.QPushButton("Yes")
        noButton = QtGui.QPushButton("No")
        yesButton.clicked.connect(self.close_fun)
        noButton.clicked.connect(self.any_first_view)
        self.second_box.addWidget(lbl1)
        self.second_box.addWidget(yesButton)
        self.second_box.addWidget(noButton)

    def any_first_view(self):
        self.clearLayout(self.second_box)
        self.first_from_view()

    def first_from_view(self):
        font = QtGui.QFont()
        font.setBold(True)
        font.setPixelSize(12)
        lbl2 = QtGui.QLabel('Welcome to the Pupilometer', self)
        lbl2.setFont(font)
        self.second_box.addWidget(lbl2)
        #self.second_box.addStretch(1)


    def first_third_view(self):
        print "first_third_view"

    def first_fourth_view(self):
        print "first_fourth_view"
        self.clearLayout(self.second_box)
        self.fourth_view()

    def fourth_view(self):
        player = Phonon.VideoPlayer()
        startButton = QtGui.QPushButton("Start")
        stopButton = QtGui.QPushButton("Stop")
        #yesButton.clicked.connect(self.close_fun)
        #noButton.clicked.connect(self.any_first_view)
        hbox = QtGui.QHBoxLayout()
        #hbox.addStretch(1)
        hbox.addWidget(startButton)
        hbox.addWidget(stopButton)
        self.second_box.addWidget(player)
        #self.second_box.addWidget(startButton)
        #self.second_box.addWidget(stopButton)
        #self.second_box.addStretch(1)
        self.second_box.addLayout(hbox)


    def first_fifth_view(self):
        print "first_fifth_view"

    def first_sixth_view(self):
        print "first_sixth_view"
        self.clearLayout(self.second_box)
        self.sixth_view()

    def sixth_view(self):
        print "hello"
        name = QtGui.QLabel('Name')
        age = QtGui.QLabel('Age')
        gender = QtGui.QLabel('Gender')
        patentID = QtGui.QLabel('Patient ID')

        nameEdit = QtGui.QLineEdit()
        ageEdit = QtGui.QLineEdit()
        patientIDEdit = QtGui.QLineEdit()

        self.b1 = QtGui.QRadioButton("Male")
        self.b2 = QtGui.QRadioButton("Female")

        self.b1.toggled.connect(lambda:self.btnstate(self.b1))
        self.b2.toggled.connect(lambda:self.btnstate(self.b2))

        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        #s = QtGui.QScrollArea()
        #grid.addWidget(s)

        grid.addWidget(name, 1, 0)
        grid.addWidget(nameEdit, 1, 1)

        grid.addWidget(age, 2, 0)
        grid.addWidget(ageEdit, 2, 1)

        grid.addWidget(gender,3,0)
        grid.addWidget(self.b1,3,1)
        grid.addWidget(self.b2,3,2)

        grid.addWidget(patentID, 4, 0)
        grid.addWidget(patientIDEdit, 4, 1)

        #s.setWidget(grid)


        self.second_box.addLayout(grid)

    def btnstate(self,b):

      if b.text() == "Button1":
         if b.isChecked() == True:
            print b.text()+" is selected"
         else:
            print b.text()+" is deselected"

      if b.text() == "Button2":
         if b.isChecked() == True:
            print b.text()+" is selected"
         else:
            print b.text()+" is deselected"


    #def remove_view(self):
    #    for cnt in reversed(range(self.second_box.count())):
    #        # takeAt does both the jobs of itemAt and removeWidget
    #        # namely it removes an item and returns it
    #        widget = self.second_box.takeAt(cnt).widget()
    #
    #        if widget is not None: 
    #            # widget will be None if the item is a layout
    #            widget.deleteLater()

    def clearLayout(self, layout):
        if layout is not None:
            while layout.count():
                item = layout.takeAt(0)
                widget = item.widget()
                if widget is not None:
                    widget.deleteLater()
                else:
                    self.clearLayout(item.layout())

    def close_fun(self):
        print "Closing the Window"
        sys.exit()

    def checkItems(self):
        QtGui.QMessageBox.information(self, 'Count',"You have %s Items in Layout" % self.second_box.count(), QtGui.QMessageBox.Ok)

    def center(self):

        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    ex.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Видеопроигрыватель Phonon имеет функцию 2nd_view.

0 ответов

Другие вопросы по тегам