我们可以在 Pyqt 中显示相机馈送吗?我只能通过 python 中的 opencv 窗口显示一个简单的视图。我想在显示 pyqt 窗口时添加更多选项。
是的,您可以使用 QLabel
并设置标签的QPixmap
.模糊地类似于:
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))
其中frame
是相机帧数据。
在这种情况下,请考虑使用 QGraphicsView。它不仅是一种显示相机图像的方式,而且您可以绘制其他线条,或者根据需要在其上放置文本。首先启动它:
# 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)
稍后您将相机图像放入其中进行显示:
image = QImage(camera_image, w, h, w, QImage.Format_Grayscale8)
self.image_item.setPixmap(QPixmap.fromImage(image))
self.view.fitInView(self.image_item)