Add QT widgets

This commit is contained in:
2023-06-25 16:07:05 +02:00
parent 20d8872930
commit 8b1bec6fa5

View File

@@ -16,46 +16,110 @@ Description:
*/
#include <iostream>
#include <opencv2/opencv.hpp>
#include <QApplication>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSlider>
#include <QFileDialog>
#include <QMessageBox>
#include <QImage>
#include "tv_denoising.hpp"
// Global variables for GUI elements
QLabel* originalImageLabel;
QLabel* resultImageLabel;
QLineEdit* inputImagePathEdit;
QLineEdit* outputImagePathEdit;
QSlider* lambdaSlider;
QSlider* iterationsSlider;
void updateDenoisedImage()
{
}
void openInputImage()
{
QString filePath = QFileDialog::getOpenFileName(nullptr, "Select Input Image");
if (!filePath.isEmpty())
inputImagePathEdit->setText(filePath);
}
void openOutputImage()
{
QString filePath = QFileDialog::getSaveFileName(nullptr, "Select Output Image");
if (!filePath.isEmpty())
outputImagePathEdit->setText(filePath);
}
int main(int argc, char** argv)
{
// Check if the required arguments are provided
if (argc < 3)
{
std::cerr << "Usage: ./TV_Denoising_CUDA <input_image> <output_image> [<lambda>] [<iterations>]" << std::endl;
return 1;
}
QApplication app(argc, argv);
// Read the input arguments
std::string inputImagePath = argv[1];
std::string outputImagePath = argv[2];
float lambda = 0.02;
int iterations = 10;
// Create the main window
QWidget window;
window.setWindowTitle("TV Image Denoising");
window.resize(800, 600);
// Check if optional arguments are provided and update the corresponding variables
if (argc >= 4)
lambda = std::stof(argv[3]);
if (argc >= 5)
iterations = std::stoi(argv[4]);
// Create the layout
QVBoxLayout* layout = new QVBoxLayout(&window);
// Read the input image
cv::Mat image = cv::imread(inputImagePath, cv::IMREAD_GRAYSCALE);
// Create the original image label
originalImageLabel = new QLabel("Original Image");
layout->addWidget(originalImageLabel);
// Check if the image was successfully loaded
if (image.empty())
{
std::cerr << "Failed to read the input image." << std::endl;
return 1;
}
// Create the result image label
resultImageLabel = new QLabel("Result Image");
layout->addWidget(resultImageLabel);
// Perform TV denoising
TVDenoising(image, lambda, iterations);
// Create the input image path input field
QHBoxLayout* inputLayout = new QHBoxLayout;
QLabel* inputLabel = new QLabel("Input Image:");
inputImagePathEdit = new QLineEdit;
QPushButton* inputBrowseButton = new QPushButton("Browse");
QObject::connect(inputBrowseButton, &QPushButton::clicked, openInputImage);
inputLayout->addWidget(inputLabel);
inputLayout->addWidget(inputImagePathEdit);
inputLayout->addWidget(inputBrowseButton);
layout->addLayout(inputLayout);
// Display and save the denoised image
cv::imshow("Denoised Image", image);
cv::waitKey(0);
cv::imwrite(outputImagePath, image);
// Create the output image path input field
QHBoxLayout* outputLayout = new QHBoxLayout;
QLabel* outputLabel = new QLabel("Output Image:");
outputImagePathEdit = new QLineEdit;
QPushButton* outputBrowseButton = new QPushButton("Browse");
QObject::connect(outputBrowseButton, &QPushButton::clicked, openOutputImage);
outputLayout->addWidget(outputLabel);
outputLayout->addWidget(outputImagePathEdit);
outputLayout->addWidget(outputBrowseButton);
layout->addLayout(outputLayout);
return 0;
}
// Create the lambda slider
QLabel* lambdaLabel = new QLabel("Lambda:");
lambdaSlider = new QSlider(Qt::Horizontal);
lambdaSlider->setMinimum(0);
lambdaSlider->setMaximum(100);
layout->addWidget(lambdaLabel);
layout->addWidget(lambdaSlider);
// Create the iterations slider
QLabel* iterationsLabel = new QLabel("Iterations:");
iterationsSlider = new QSlider(Qt::Horizontal);
iterationsSlider->setMinimum(1);
iterationsSlider->setMaximum(100);
layout->addWidget(iterationsLabel);
layout->addWidget(iterationsSlider);
// Create the denoise button
QPushButton* denoiseButton = new QPushButton("Denoise");
QObject::connect(denoiseButton, &QPushButton::clicked, updateDenoisedImage);
layout->addWidget(denoiseButton);
// Show the main window
window.show();
return app.exec();
}