implemented contrast slider
This commit is contained in:
parent
3106479fcc
commit
a39a34852c
|
@ -94,15 +94,9 @@ endif()
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
find_package(OpenCV REQUIRED)
|
find_package(OpenCV REQUIRED)
|
||||||
|
|
||||||
# include_directories("/usr/include/opencv4")
|
|
||||||
include_directories( ${OpenCV_INCLUDE_DIRS})
|
include_directories( ${OpenCV_INCLUDE_DIRS})
|
||||||
target_link_libraries(checks-parser PRIVATE -lzbar)
|
target_link_libraries(checks-parser PRIVATE -lzbar)
|
||||||
target_link_libraries(checks-parser PRIVATE -ltesseract)
|
target_link_libraries(checks-parser PRIVATE -ltesseract)
|
||||||
target_link_libraries(checks-parser PRIVATE -lcurl)
|
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 ${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)
|
|
||||||
|
|
|
@ -4,23 +4,24 @@
|
||||||
#include <opencv2/imgcodecs.hpp>
|
#include <opencv2/imgcodecs.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
#include <opencv2/core/mat.hpp>
|
#include <opencv2/core/mat.hpp>
|
||||||
|
#include <QColorTransform>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <zbar.h>
|
#include <zbar.h>
|
||||||
|
|
||||||
AdjustPictureDialog::AdjustPictureDialog(QWidget *parent, std::string imagePath)
|
AdjustPictureDialog::AdjustPictureDialog(QWidget *parent, std::string imagePath)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::AdjustPictureDialog){
|
, ui(new Ui::AdjustPictureDialog)
|
||||||
|
, pixmap(QString::fromStdString(imagePath))
|
||||||
|
, img(pixmap.toImage()){
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
computeContrastLookupTable();
|
||||||
|
|
||||||
scene = new QGraphicsScene(this);
|
scene = new QGraphicsScene(this);
|
||||||
|
|
||||||
ui->graphicsView->setScene(scene);
|
ui->graphicsView->setScene(scene);
|
||||||
QGraphicsPixmapItem p;
|
|
||||||
QString path = QString::fromStdString(imagePath);
|
|
||||||
QPixmap pixmap = QPixmap(path);
|
|
||||||
scene->addPixmap(pixmap);
|
scene->addPixmap(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,12 +67,39 @@ std::string AdjustPictureDialog::decode() {
|
||||||
result = symbol->get_data();
|
result = symbol->get_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
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<int>(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<uint32_t*>(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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,11 @@ public:
|
||||||
explicit AdjustPictureDialog(QWidget *parent = nullptr, std::string imagePath = "");
|
explicit AdjustPictureDialog(QWidget *parent = nullptr, std::string imagePath = "");
|
||||||
~AdjustPictureDialog();
|
~AdjustPictureDialog();
|
||||||
std::string decode();
|
std::string decode();
|
||||||
|
QPixmap pixmap;
|
||||||
|
QImage img;
|
||||||
|
|
||||||
|
void computeContrastLookupTable();
|
||||||
|
std::vector<unsigned short> contrastLUT[100];
|
||||||
signals:
|
signals:
|
||||||
void decodedData(std::string data);
|
void decodedData(std::string data);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ class ImageRedactor : public QGraphicsView
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ImageRedactor(QWidget *parent = nullptr);
|
ImageRedactor(QWidget *parent = nullptr);
|
||||||
|
QGraphicsScene *scene;
|
||||||
protected:
|
protected:
|
||||||
void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
|
@ -20,7 +21,6 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGraphicsScene *scene;
|
|
||||||
QGraphicsPixmapItem *item;
|
QGraphicsPixmapItem *item;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,13 +58,14 @@ std::string MainWindow::makeRequestToOfd(std::string captcha) {
|
||||||
ui->total_edit->text().toDouble() * 100,
|
ui->total_edit->text().toDouble() * 100,
|
||||||
captcha);
|
captcha);
|
||||||
|
|
||||||
return checkContent
|
return checkContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::receiveSolvedCaptcha(std::string captcha) {
|
void MainWindow::receiveSolvedCaptcha(std::string captcha) {
|
||||||
|
|
||||||
std::string check_content = makeRequestToOfd(captcha);
|
std::string check_content = makeRequestToOfd(captcha);
|
||||||
|
|
||||||
|
std::cout << check_content << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue