From a39a34852c59ebb554d0c71e8e81cd374a1447b1 Mon Sep 17 00:00:00 2001 From: leca Date: Mon, 25 Nov 2024 04:07:56 +0300 Subject: [PATCH] implemented contrast slider --- CMakeLists.txt | 6 ----- adjustpicturedialog.cpp | 44 +++++++++++++++++++++++++++------- adjustpicturedialog.h | 4 ++++ image_redactor/imageredactor.h | 2 +- mainwindow.cpp | 3 ++- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2695750..25e7762 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,15 +94,9 @@ endif() find_package(PkgConfig REQUIRED) find_package(OpenCV REQUIRED) -# include_directories("/usr/include/opencv4") include_directories( ${OpenCV_INCLUDE_DIRS}) target_link_libraries(checks-parser PRIVATE -lzbar) target_link_libraries(checks-parser PRIVATE -ltesseract) target_link_libraries(checks-parser PRIVATE -lcurl) -# pkg_search_module(opencv REQUIRED IMPORTED_TARGET opencv) -# target_link_libraries(checks-parser PRIVATE -lopencv4) target_link_libraries( checks-parser PRIVATE ${OpenCV_LIBS} ) -# target_link_libraries(checks-parser PRIVATE PkgConfig::opencv) -# target_link_libraries(checks-parser PRIVATE ${OpenCV_LIBS}) -# target_link_libraries(checks-parser PRIVATE -lopencv) diff --git a/adjustpicturedialog.cpp b/adjustpicturedialog.cpp index 9f50413..40d6634 100644 --- a/adjustpicturedialog.cpp +++ b/adjustpicturedialog.cpp @@ -4,23 +4,24 @@ #include #include #include -#include #include +#include #include #include #include AdjustPictureDialog::AdjustPictureDialog(QWidget *parent, std::string imagePath) : QDialog(parent) - , ui(new Ui::AdjustPictureDialog){ + , ui(new Ui::AdjustPictureDialog) + , pixmap(QString::fromStdString(imagePath)) + , img(pixmap.toImage()){ ui->setupUi(this); + computeContrastLookupTable(); + scene = new QGraphicsScene(this); ui->graphicsView->setScene(scene); - QGraphicsPixmapItem p; - QString path = QString::fromStdString(imagePath); - QPixmap pixmap = QPixmap(path); scene->addPixmap(pixmap); } @@ -66,12 +67,39 @@ std::string AdjustPictureDialog::decode() { result = symbol->get_data(); } - - return result; } -void AdjustPictureDialog::on_contrastSlider_sliderMoved(int position) { +void AdjustPictureDialog::computeContrastLookupTable() { + for (int contrastValue = 0; contrastValue < 100; ++contrastValue) { + double contrast = contrastValue / 50.0; + for (int i = 0; i < 256; ++i) { + unsigned short correctedValue = std::clamp(static_cast(128 + contrast * (i - 128)), 0, 255); + contrastLUT[contrastValue].push_back(correctedValue); + } + } +} + +void AdjustPictureDialog::on_contrastSlider_sliderMoved(int position) { + QImage image = img.copy(); + + uint32_t* pixels = reinterpret_cast(image.bits()); + int width = image.width(); + int height = image.height(); + + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + QRgb rgb = pixels[y * width + x]; + pixels[y * width + x] = qRgba( + contrastLUT[position][qRed(rgb)], + contrastLUT[position][qGreen(rgb)], + contrastLUT[position][qBlue(rgb)], + qAlpha(rgb)); + } + } + + scene->clear(); + scene->addPixmap(QPixmap::fromImage(image)); } diff --git a/adjustpicturedialog.h b/adjustpicturedialog.h index 9fefcb2..b3feef9 100644 --- a/adjustpicturedialog.h +++ b/adjustpicturedialog.h @@ -16,7 +16,11 @@ public: explicit AdjustPictureDialog(QWidget *parent = nullptr, std::string imagePath = ""); ~AdjustPictureDialog(); std::string decode(); + QPixmap pixmap; + QImage img; + void computeContrastLookupTable(); + std::vector contrastLUT[100]; signals: void decodedData(std::string data); diff --git a/image_redactor/imageredactor.h b/image_redactor/imageredactor.h index bf050ff..96444d9 100644 --- a/image_redactor/imageredactor.h +++ b/image_redactor/imageredactor.h @@ -12,6 +12,7 @@ class ImageRedactor : public QGraphicsView Q_OBJECT public: ImageRedactor(QWidget *parent = nullptr); + QGraphicsScene *scene; protected: void wheelEvent(QWheelEvent *event); @@ -20,7 +21,6 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private: - QGraphicsScene *scene; QGraphicsPixmapItem *item; }; diff --git a/mainwindow.cpp b/mainwindow.cpp index ed3b1cb..fa9fbd2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -58,13 +58,14 @@ std::string MainWindow::makeRequestToOfd(std::string captcha) { ui->total_edit->text().toDouble() * 100, captcha); - return checkContent + return checkContent; } void MainWindow::receiveSolvedCaptcha(std::string captcha) { std::string check_content = makeRequestToOfd(captcha); + std::cout << check_content << std::endl; }