首页 > 解决方案 > 连续显示文件夹中的多个图像

问题描述

我能够在标签中显示第一张图像,但我正在寻找的是显示文件夹中的所有图像以连续并排显示,并在有任何更新时自动刷新图像。如何根据文件夹中图像文件的数量创建多个标签并在其上设置图像。例如:如果我的文件夹包含 Nicolascage、Tom Hanks、Sandra Bullocks 的图像,那么他们的所有图像都应该放在一行中,如果新图像替换现有图像,那么它应该自动刷新。

到目前为止我取得的成就: 在此处输入图像描述

我的代码:

import cv2,os
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from VideoFaceDetectiondup import vidcaptureface
from PyQt5 import QtCore, QtGui, QtWidgets #works for pyqt5

class MainWindow(QWidget):
    def __init__(self, camera_index=0, fps=30):
        super().__init__()

        self.capture = cv2.VideoCapture(camera_index)
        self.dimensions = self.capture.read()[1].shape[1::-1]

        scene = QGraphicsScene(self)
        pixmap = QPixmap(*self.dimensions)
        self.pixmapItem = scene.addPixmap(pixmap)

        view = QGraphicsView(self)
        view.setScene(scene)

        text = QLabel('facecam 1.0', self)
        label = QLabel()
        pixmap = QPixmap("messigray_1.png")
        label.setPixmap(pixmap)
        label.show()
        # label.setGeometry(QtCore.QRect(1270, 1280, 1200, 1200))   

        layout = QVBoxLayout(self)
        layout.addWidget(view)
        layout.addWidget(text)
        layout.addWidget(label)



        timer = QTimer(self)
        timer.setInterval(int(1000/fps))
        timer.timeout.connect(self.get_frame)
        timer.start()


    def get_frame(self):
        _, frame = self.capture.read()
        frame=vidcaptureface(frame)
        image = QImage(frame, *self.dimensions, QImage.Format_RGB888).rgbSwapped()
        pixmap = QPixmap.fromImage(image)
        self.pixmapItem.setPixmap(pixmap)





app = QApplication([])
win = MainWindow()
win.show()
app.exec()

标签: pythonpyqtpyqt5

解决方案


推荐阅读