python - 连续显示文件夹中的多个图像
问题描述
我能够在标签中显示第一张图像,但我正在寻找的是显示文件夹中的所有图像以连续并排显示,并在有任何更新时自动刷新图像。如何根据文件夹中图像文件的数量创建多个标签并在其上设置图像。例如:如果我的文件夹包含 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()
解决方案
推荐阅读
- node.js - Sequelize - 如何使用 ignoreDuplicates 批量创建并仅返回插入的项目?
- python - Python h5py - “形状元组与数据不兼容”错误
- python - 为什么每行中的方法链接与方法会导致进程被杀死或内存不足?
- powerbi - PowerBI Refresh - 仅附加在文件夹中的最新文件中
- python - 替换字符串中的特殊字符
- python - Tornado websocket 与动态 MongoDB Motor 手表
- python - 如何在python中运行多个fedora命令
- javascript - #jquery 对话框不是函数
- javascript - 如何自定义jQuery图像预览代码
- synology - 淘汰唯一的卷,保存重要的文件