Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screenshot from QT buffer #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/scanner/AutoBarcodeScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ THE SOFTWARE.
#include <QStandardPaths>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusConnection>
#include <QGuiApplication>
#include <QQuickWindow>

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -60,6 +62,15 @@ AutoBarcodeScanner::AutoBarcodeScanner(QObject * parent)
createConnections();
m_timeoutTimer->setSingleShot(true);
connect(m_timeoutTimer, SIGNAL(timeout()), this, SLOT(slotScanningTimeout()));

QGuiApplication *app = qobject_cast<QGuiApplication*>(qApp);

foreach (QWindow *win, app->allWindows()) {
QQuickWindow *quickWin = qobject_cast<QQuickWindow*>(win);
if (quickWin) {
m_mainWindow = quickWin;
}
}
}

AutoBarcodeScanner::~AutoBarcodeScanner() {
Expand Down Expand Up @@ -231,29 +242,35 @@ void AutoBarcodeScanner::processDecode() {
m_scanProcessMutex.unlock();

if (scanActive) {
createScreeshot();
QImage screenshot(m_decoder->getCaptureLocation());
saveDebugImage(screenshot, "debug_screenshot.jpg");
QImage screenshot = m_mainWindow->grabWindow();
//maybe
//saveDebugImage(screenshot, "debug_screenshot.jpg");

// crop the image - we need only the viewfinder
QImage copy = screenshot.copy(m_viewFinderRect);
copy.save(m_decoder->getCaptureLocation());
saveDebugImage(copy, "debug_cropped.jpg");
//maybe
//copy.save(m_decoder->getCaptureLocation());
//saveDebugImage(copy, "debug_cropped.jpg");



qDebug() << "decoding cropped screenshot ...";
result = m_decoder->decodeBarcodeFromCache();
result = m_decoder->decodeBarcodeFromImage(copy);

copy.save(m_decoder->getCaptureLocation());
code = result["content"].toString();

if (code.isEmpty()) {
// try the other orientation for 1D bar code
QTransform transform;
transform.rotate(90);
copy = copy.transformed(transform);
//maybe still do it in debug
copy.save(m_decoder->getCaptureLocation());
saveDebugImage(copy, "debug_transformed.jpg");

qDebug() << "decoding rotated screenshot ...";
result = m_decoder->decodeBarcodeFromCache();
result = m_decoder->decodeBarcodeFromImage(copy);
code = result["content"].toString();
}

Expand Down
3 changes: 3 additions & 0 deletions src/scanner/AutoBarcodeScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ THE SOFTWARE.
#include <QThread>
#include <QColor>
#include <QtConcurrent>
#include <QGuiApplication>
#include <QQuickWindow>
#include <QtQml/qqmlparserstatus.h>
#include "BarcodeDecoder.h"

Expand Down Expand Up @@ -129,6 +131,7 @@ public slots:

QMutex m_scanProcessMutex;
QWaitCondition m_scanProcessStopped;
QQuickWindow* m_mainWindow;

// options
QRect m_viewFinderRect;
Expand Down
4 changes: 4 additions & 0 deletions src/scanner/BarcodeDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ QVariantHash BarcodeDecoder::decodeBarcodeFromCache() {
QVariantHash result = decoder->decodeImageEx(img);
return result;
}
QVariantHash BarcodeDecoder::decodeBarcodeFromImage(QImage &img) {
QVariantHash result = decoder->decodeImageEx(img);
return result;
}
2 changes: 1 addition & 1 deletion src/scanner/BarcodeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BarcodeDecoder : public QObject
virtual ~BarcodeDecoder();

QVariantHash decodeBarcodeFromCache();

QVariantHash decodeBarcodeFromImage(QImage &img);
void setDecoderFormat(const int &format);
QString getCaptureLocation() const;

Expand Down