Add QT widgets
This commit is contained in:
128
src/main.cpp
128
src/main.cpp
@@ -16,46 +16,110 @@ Description:
|
|||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <opencv2/opencv.hpp>
|
#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"
|
#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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
// Check if the required arguments are provided
|
QApplication app(argc, argv);
|
||||||
if (argc < 3)
|
|
||||||
{
|
|
||||||
std::cerr << "Usage: ./TV_Denoising_CUDA <input_image> <output_image> [<lambda>] [<iterations>]" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the input arguments
|
// Create the main window
|
||||||
std::string inputImagePath = argv[1];
|
QWidget window;
|
||||||
std::string outputImagePath = argv[2];
|
window.setWindowTitle("TV Image Denoising");
|
||||||
float lambda = 0.02;
|
window.resize(800, 600);
|
||||||
int iterations = 10;
|
|
||||||
|
|
||||||
// Check if optional arguments are provided and update the corresponding variables
|
// Create the layout
|
||||||
if (argc >= 4)
|
QVBoxLayout* layout = new QVBoxLayout(&window);
|
||||||
lambda = std::stof(argv[3]);
|
|
||||||
if (argc >= 5)
|
|
||||||
iterations = std::stoi(argv[4]);
|
|
||||||
|
|
||||||
// Read the input image
|
// Create the original image label
|
||||||
cv::Mat image = cv::imread(inputImagePath, cv::IMREAD_GRAYSCALE);
|
originalImageLabel = new QLabel("Original Image");
|
||||||
|
layout->addWidget(originalImageLabel);
|
||||||
|
|
||||||
// Check if the image was successfully loaded
|
// Create the result image label
|
||||||
if (image.empty())
|
resultImageLabel = new QLabel("Result Image");
|
||||||
{
|
layout->addWidget(resultImageLabel);
|
||||||
std::cerr << "Failed to read the input image." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform TV denoising
|
// Create the input image path input field
|
||||||
TVDenoising(image, lambda, iterations);
|
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
|
// Create the output image path input field
|
||||||
cv::imshow("Denoised Image", image);
|
QHBoxLayout* outputLayout = new QHBoxLayout;
|
||||||
cv::waitKey(0);
|
QLabel* outputLabel = new QLabel("Output Image:");
|
||||||
cv::imwrite(outputImagePath, 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();
|
||||||
|
}
|
Reference in New Issue
Block a user