我能够在标签中显示第一张图像,但是我要查找的是将要并排显示的文件夹中的所有图像并排显示,如果有更新,则自动刷新图像。如何基于文件夹中图像文件的数量创建多个标签并在其上设置图像。例如:如果我的文件夹中包含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()