73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
|
#include "adjustpicturedialog.h"
|
||
|
#include "ui_adjustpicturedialog.h"
|
||
|
#include "utils/utils.h"
|
||
|
#include <opencv2/imgcodecs.hpp>
|
||
|
#include <opencv2/imgproc.hpp>
|
||
|
#include <string>
|
||
|
#include <iostream>
|
||
|
#include <opencv2/core/mat.hpp>
|
||
|
#include <QFileDialog>
|
||
|
#include <QMessageBox>
|
||
|
#include <zbar.h>
|
||
|
|
||
|
AdjustPictureDialog::AdjustPictureDialog(QWidget *parent, std::string imagePath)
|
||
|
: QDialog(parent)
|
||
|
, ui(new Ui::AdjustPictureDialog){
|
||
|
ui->setupUi(this);
|
||
|
|
||
|
scene = new QGraphicsScene(this);
|
||
|
|
||
|
ui->graphicsView->setScene(scene);
|
||
|
QGraphicsPixmapItem p;
|
||
|
QString path = QString::fromStdString(imagePath);
|
||
|
QPixmap pixmap = QPixmap(path);
|
||
|
scene->addPixmap(pixmap);
|
||
|
}
|
||
|
|
||
|
AdjustPictureDialog::~AdjustPictureDialog() {
|
||
|
delete ui;
|
||
|
}
|
||
|
|
||
|
void AdjustPictureDialog::accept() {
|
||
|
QPixmap pixMap = ui->graphicsView->grab();
|
||
|
pixMap.save(QString::fromStdString(get_path_relative_to_home(".local/share/checks_parser/temp.png")));
|
||
|
|
||
|
std::string result = decode();
|
||
|
|
||
|
if (result == "") {
|
||
|
QMessageBox infoDialog;
|
||
|
infoDialog.setText("QR code was not detected on that image. Please edit it again or enter data manually");
|
||
|
infoDialog.setIcon(QMessageBox::Warning);
|
||
|
infoDialog.setWindowTitle("No QR code");
|
||
|
infoDialog.exec();
|
||
|
} else {
|
||
|
emit decodedData(result);
|
||
|
QDialog::accept();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
std::string AdjustPictureDialog::decode() {
|
||
|
cv::Mat im = cv::imread(get_path_relative_to_home(".local/share/checks_parser/temp.png"));
|
||
|
|
||
|
zbar::ImageScanner scanner;
|
||
|
scanner.set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1);
|
||
|
scanner.set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_TEST_INVERTED, 1);
|
||
|
|
||
|
cv::Mat imGray;
|
||
|
cv::cvtColor(im, imGray, cv::COLOR_BGR2GRAY);
|
||
|
|
||
|
zbar::Image image(im.cols, im.rows, "Y800", (uchar *) imGray.data, im.cols * im.rows);
|
||
|
int n = scanner.scan(image);
|
||
|
|
||
|
std::string result = "";
|
||
|
|
||
|
for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
|
||
|
result = symbol->get_data();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
return result;
|
||
|
}
|