Initial Linux Qt OpenCV project
This commit is contained in:
11
app/include/ImageConverter.h
Normal file
11
app/include/ImageConverter.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <QImage>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
class ImageConverter final
|
||||
{
|
||||
public:
|
||||
static QImage matToQImage(const cv::Mat &mat);
|
||||
static cv::Mat qImageToMat(const QImage &image);
|
||||
};
|
||||
23
app/include/ImageProcessor.h
Normal file
23
app/include/ImageProcessor.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
struct ProcessResult
|
||||
{
|
||||
cv::Mat image;
|
||||
QString description;
|
||||
};
|
||||
|
||||
class ImageProcessor final
|
||||
{
|
||||
public:
|
||||
static ProcessResult rotate(const cv::Mat &source, double angleDegrees);
|
||||
static ProcessResult scale(const cv::Mat &source, double factor);
|
||||
static ProcessResult translate(const cv::Mat &source, int dx, int dy);
|
||||
static ProcessResult extractTargets(const cv::Mat &source);
|
||||
static ProcessResult classifySimple(const cv::Mat &source);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ProcessResult)
|
||||
35
app/include/ImageView.h
Normal file
35
app/include/ImageView.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
|
||||
class QGraphicsPixmapItem;
|
||||
class QGraphicsScene;
|
||||
class QWheelEvent;
|
||||
class QMouseEvent;
|
||||
|
||||
class ImageView final : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ImageView(QWidget *parent = nullptr);
|
||||
|
||||
void setImage(const QImage &image);
|
||||
void clearImage();
|
||||
void fitImageToView();
|
||||
bool hasImage() const;
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void resetSceneRect();
|
||||
|
||||
QGraphicsScene *scene_ = nullptr;
|
||||
QGraphicsPixmapItem *pixmapItem_ = nullptr;
|
||||
QPixmap pixmap_;
|
||||
double zoomFactor_ = 1.0;
|
||||
};
|
||||
33
app/include/ImageWorker.h
Normal file
33
app/include/ImageWorker.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "ImageProcessor.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaType>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
Q_DECLARE_METATYPE(cv::Mat)
|
||||
|
||||
class ImageWorker final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class Operation {
|
||||
Rotate,
|
||||
Scale,
|
||||
Translate,
|
||||
ExtractTargets,
|
||||
ClassifySimple
|
||||
};
|
||||
Q_ENUM(Operation)
|
||||
|
||||
public Q_SLOTS:
|
||||
void process(cv::Mat image, ImageWorker::Operation operation, double value, int dx, int dy);
|
||||
|
||||
Q_SIGNALS:
|
||||
void finished(ProcessResult result);
|
||||
void failed(QString message);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ImageWorker::Operation)
|
||||
72
app/include/MainWindow.h
Normal file
72
app/include/MainWindow.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "ImageWorker.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QThread>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
class QAction;
|
||||
class QLabel;
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
class QPushButton;
|
||||
class ImageView;
|
||||
|
||||
class MainWindow final : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void processRequested(cv::Mat image, ImageWorker::Operation operation, double value, int dx, int dy);
|
||||
|
||||
private Q_SLOTS:
|
||||
void openImage();
|
||||
void saveImage();
|
||||
void saveImageAs();
|
||||
void resetToOriginal();
|
||||
void onProcessFinished(ProcessResult result);
|
||||
void onProcessFailed(const QString &message);
|
||||
void rotateLeft();
|
||||
void rotateRight();
|
||||
void scaleUp();
|
||||
void scaleDown();
|
||||
void translateUp();
|
||||
void translateDown();
|
||||
void translateLeft();
|
||||
void translateRight();
|
||||
void extractTargets();
|
||||
void classifyImage();
|
||||
|
||||
private:
|
||||
void buildUi();
|
||||
void setupWorkerThread();
|
||||
void updateViews();
|
||||
void setBusy(bool busy);
|
||||
bool ensureHasImage() const;
|
||||
void requestProcess(ImageWorker::Operation operation, double value = 0.0, int dx = 0, int dy = 0);
|
||||
bool writeCurrentImageTo(const QString &path);
|
||||
|
||||
ImageView *originalView_ = nullptr;
|
||||
ImageView *processedView_ = nullptr;
|
||||
QLabel *infoLabel_ = nullptr;
|
||||
QLabel *statusLabel_ = nullptr;
|
||||
QDoubleSpinBox *scaleSpin_ = nullptr;
|
||||
QDoubleSpinBox *angleSpin_ = nullptr;
|
||||
QSpinBox *translateSpin_ = nullptr;
|
||||
|
||||
QAction *saveAction_ = nullptr;
|
||||
QAction *saveAsAction_ = nullptr;
|
||||
|
||||
QThread workerThread_;
|
||||
ImageWorker *worker_ = nullptr;
|
||||
|
||||
cv::Mat originalImage_;
|
||||
cv::Mat processedImage_;
|
||||
QString currentPath_;
|
||||
bool busy_ = false;
|
||||
};
|
||||
Reference in New Issue
Block a user