图片归档工具

# 图片删选工具。指定图片目录,点击按钮,自动将图片归档到当前目录下对应的文件夹中
# 比如点击正确按钮,会将当前图片移动到当前目录下的正确文件夹下

# 用法:
# 1. 点击“请选择文件路径”按钮,选择图片所在的文件夹
# 2. 点击“正确”、“错误”、“待定”按钮,将当前图片归档到对应的文件夹下
# 3. 点击“正确”、“错误”、“待定”按钮后,自动加载下一张图片

import sys
import os
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QVBoxLayout, QWidget, QFileDialog
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt

class ImageClassifierApp(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Image Classifier")
        self.setGeometry(100, 100, 800, 600)

        self.image_label = QLabel(self)
        self.image_label.setAlignment(Qt.AlignCenter)
        self.image_label.setFixedWidth(640)
        self.image_label.setFixedHeight(640)

        self.load_button = QPushButton("请选择文件路径", self)
        self.load_button.clicked.connect(self.load_images)

        self.correct_button = QPushButton("正确", self)
        self.correct_button.clicked.connect(self.move_and_load_next)

        self.incorrect_button = QPushButton("错误", self)
        self.incorrect_button.clicked.connect(self.move_and_load_next)

        self.pending_button = QPushButton("待定", self)
        self.pending_button.clicked.connect(self.move_and_load_next)

        layout = QVBoxLayout()
        layout.addWidget(self.image_label)
        layout.addWidget(self.load_button)
        layout.addWidget(self.correct_button)
        layout.addWidget(self.incorrect_button)
        layout.addWidget(self.pending_button)

        central_widget = QWidget()
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

        self.image_paths = []
        self.current_index = 0

    def load_images(self):
        folder_path = QFileDialog.getExistingDirectory(self, "请选择文件路径")
        if folder_path:
            self.image_paths = [os.path.join(folder_path, filename) for filename in os.listdir(folder_path) if filename.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.webp'))]
            self.current_index = 0
            self.load_current_image()

    def load_current_image(self):
        if 0 <= self.current_index < len(self.image_paths):
            pixmap = QPixmap(self.image_paths[self.current_index])
            max_width = self.image_label.maximumWidth()
            max_height = self.image_label.maximumHeight()
            pixmap = pixmap.scaled(max_width, max_height, Qt.KeepAspectRatio, Qt.SmoothTransformation)
            self.image_label.setPixmap(pixmap)
        else:
            self.image_label.clear()

    def move_and_load_next(self):
        if self.current_index >= len(self.image_paths):
            return
        destination_folder = self.sender().text()
        source_path = self.image_paths[self.current_index]
        filename = os.path.basename(source_path)
        root_folder = os.path.dirname(source_path)
        destination_folder = os.path.join(root_folder, destination_folder)
        destination_path = os.path.join(destination_folder, filename)
        
        os.makedirs(destination_folder, exist_ok=True)
        os.rename(source_path, destination_path)
        
        self.current_index += 1
        self.load_current_image()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = ImageClassifierApp()
    window.show()
    sys.exit(app.exec_())


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值