No Viewfinder Available While Trying To Display Webcam With Pyside2
I am working on Ubuntu 20.04 with Python3 and PySide2, Qt is version 5. I wrote this simple Python script in order to test the ability to save webcam video for a larger project I w
Solution 1:
QCamera needs a QCameraViewfinder which is a widget that allows to display the information captured by QCamera, so you cannot pass a QFrame to it.
import sys
from PySide2.QtWidgets import QApplication, QMainWindow
from PySide2.QtMultimedia import QCamera, QCameraInfo
from PySide2.QtMultimediaWidgets import QCameraViewfinder
from MainWindow import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
for info in QCameraInfo.availableCameras():
self.camera_combobox.addItem(info.description(), info)
self.connect_btn.clicked.connect(self.connect_btn_clicked)
self.view_finder = QCameraViewfinder()
self.frame.layout().addWidget(self.view_finder)
def connect_btn_clicked(self):
info = self.camera_combobox.currentData()
self.camera = QCamera(info)
self.camera.setViewfinder(self.view_finder)
self.camera.start()
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
Post a Comment for "No Viewfinder Available While Trying To Display Webcam With Pyside2"