Can we display a camera feed in Pyqt? I can only display a simple view through the opencv window in python. I want to add some more options while displaying the pyqt window.
Yes, you can do it using QLabel and setting the label's QPixmap. Something vaguely along the lines of:
label = QtGui.QLabel()
image = QtGui.QImage(
frame,
frame.shape[1],
frame.shape[0],
frame.shape[1] * 3,
QtGui.QImage.Format_RGB888
)
label.setPixmap(QtGui.QPixmap.fromImage(image))
where frame is your camera frame data.
In that case, consider using a QGraphicsView. Its not only a way to display your camera image, but you can draw additional lines, or put text on it if you want. First you initiate it:
# Create scene
self.image_item = QGraphicsPixmapItem()
scene = QGraphicsScene(self)
scene.addItem(self.image_item)
# Create GraphicView display
self.view = QGraphicsView(scene, self)
# Adding right click menus
self.view.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.zoomout_action = QAction("Fit canvas", self)
self.view.addAction(self.zoomout_action)
And later you put the camera image in it for display:
image = QImage(camera_image, w, h, w, QImage.Format_Grayscale8)
self.image_item.setPixmap(QPixmap.fromImage(image))
self.view.fitInView(self.image_item)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With