implemented contrast slider
This commit is contained in:
parent
3106479fcc
commit
a39a34852c
|
@ -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)
|
||||
|
|
|
@ -4,23 +4,24 @@
|
|||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <opencv2/core/mat.hpp>
|
||||
#include <QColorTransform>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <zbar.h>
|
||||
|
||||
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<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 = "");
|
||||
~AdjustPictureDialog();
|
||||
std::string decode();
|
||||
QPixmap pixmap;
|
||||
QImage img;
|
||||
|
||||
void computeContrastLookupTable();
|
||||
std::vector<unsigned short> contrastLUT[100];
|
||||
signals:
|
||||
void decodedData(std::string data);
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue