最近在看遥感图像目标检测相关的yolo10,自己在网上下载了数据集跑模型,但是跑出来的结果与数据集出处的论文介绍分类有些不同,只出现了分类0的情况,怀疑是标注有问题,但是数据集太大,于是做了个小工具对标注生成的txt文件进行分析。
使用的是QTCreator,核心就是读取目录下所有的txt文件读取每个txt文件每行的第一个数字,并且最后统计结果。
运行结果
功能基本实现,发现确实标注都是0,哭死,希望有做计算机视觉的大佬可以帮助。
小工具源码
mianwindow.ui
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QDropEvent>
#include <QMAp>
#include <QMainWindow>
#include <QMimeData>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();void readAllTextFilesInDirectory(const QString &directoryPath);
protected:void dragEnterEvent(QDragEnterEvent *event) override;void dropEvent(QDropEvent * event) override;
private slots:void on_toolButton_clicked();void on_pushButton_clicked();
signals:void progressUpdated(int progress);void processingFinished();private:Ui::MainWindow *ui;QString txtPath;QMap<int , int> numberCounts;};
#endif // MAINWINDOW_H
mainwindow.c
#include "mainwindow.h"
#include "ui_mainwindow.h"#include <QDir>
#include <QFileInfoList>
#include <QTextStream>
#include <QDebug>
#include <QFileDialog>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);// 启用拖放支持setAcceptDrops(true);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::readAllTextFilesInDirectory(const QString &directoryPath)
{QDir dir(directoryPath);// 设置过滤器,只选择 .txt 文件QStringList filters;filters << "*.txt";dir.setNameFilters(filters);// 获取目录下的所有 .txt 文件QFileInfoList fileList = dir.entryInfoList();int totalFiles = fileList.size();int progessdFiles = 0;foreach (const QFileInfo &fileInfo, fileList) {if (fileInfo.isFile()) {QFile file(fileInfo.absoluteFilePath());if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {QTextStream in(&file);QString fileContent = in.readAll();file.close();// 输出文件内容qDebug() << "File:" << fileInfo.fileName();qDebug() << "Content:" << fileContent;ui->textBrowser->append("File:" + fileInfo.fileName());ui->textBrowser->append("Content:" + fileContent);ui->textBrowser->append("");// 读取每个行的第一个数字QStringList lines = fileContent.split('\n');foreach (const QString &line, lines){if (!line.isEmpty()){QString firstWord = line.trimmed().split(' ').first();bool ok;int number = firstWord.toInt(&ok);if (ok){// 记录数字的出现次数if (numberCounts.contains(number)){numberCounts[number]++;}else{numberCounts[number] = 1;}}}}progessdFiles++;int progess = (progessdFiles * 100) / totalFiles;ui->progressBar->setValue(progess);} else {qDebug() << "Failed to open file:" << fileInfo.fileName();}}}// 所有文件解析完成后,将进度条设置为 100%if (progessdFiles == totalFiles) {ui->progressBar->setValue(100);// 输出数字及其出现次数qDebug() << "Number counts:";for (auto it = numberCounts.begin(); it != numberCounts.end(); ++it) {qDebug() << it.key() << ":" << it.value();ui->textBrowser->append(QString::number(it.key()) + " : " + QString::number(it.value()));}}}void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{// 检查拖放的数据是否包含文件路径if (event->mimeData()->hasUrls()) {// 只接受 .txt 文件QList<QUrl> urls = event->mimeData()->urls();if (!urls.isEmpty() && urls.first().toString().endsWith(".txt")) {event->acceptProposedAction();}}
}void MainWindow::dropEvent(QDropEvent *event)
{// 获取拖放的文件路径QList<QUrl> urls = event->mimeData()->urls();if (!urls.isEmpty()) {QString filePath = urls.first().toLocalFile();// 检查文件路径是否为 .txt 文件if (filePath.endsWith(".txt")) {// 将文件路径显示在 QLineEdit 中ui->lineEdit->setText(filePath);// 记录文件路径txtPath = filePath;}}
}void MainWindow::on_toolButton_clicked()
{// 使用 QFileDialog 选择单个 .txt 文件QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), "/home", tr("Text Files (*.txt)"));if (!filePath.isEmpty()) {// 将文件路径显示在 QLabel 中ui->lineEdit->setText(filePath);}txtPath = filePath;
}void MainWindow::on_pushButton_clicked()
{numberCounts.clear();ui->textBrowser->clear();readAllTextFilesInDirectory(QFileInfo(txtPath).path());
}