removed qr code added image request
parent
de45695249
commit
e94dbeea4c
|
|
@ -116,6 +116,7 @@ void DevicePluginDoorbird::setupDevice(DeviceSetupInfo *info)
|
|||
connect(doorbird, &Doorbird::deviceConnected, this, &DevicePluginDoorbird::onDoorBirdConnected);
|
||||
connect(doorbird, &Doorbird::eventReveiced, this, &DevicePluginDoorbird::onDoorBirdEvent);
|
||||
connect(doorbird, &Doorbird::requestSent, this, &DevicePluginDoorbird::onDoorBirdRequestSent);
|
||||
connect(doorbird, &Doorbird::liveImageReceived, this, &DevicePluginDoorbird::onImageReceived);
|
||||
doorbird->connectToEventMonitor();
|
||||
m_doorbirdConnections.insert(device, doorbird);
|
||||
info->finish(Device::DeviceErrorNoError);
|
||||
|
|
@ -228,6 +229,15 @@ void DevicePluginDoorbird::onDoorBirdRequestSent(QUuid requestId, bool success)
|
|||
|
||||
void DevicePluginDoorbird::onImageReceived(QImage image)
|
||||
{
|
||||
Q_UNUSED(image)
|
||||
//QString code =
|
||||
Q_UNUSED(image);
|
||||
Doorbird *doorbird = static_cast<Doorbird *>(sender());
|
||||
Device *device = m_doorbirdConnections.key(doorbird);
|
||||
if (!device)
|
||||
return;
|
||||
//TODO add QR code detection
|
||||
Event event;
|
||||
event.setDeviceId(device->id());
|
||||
event.setEventTypeId(doorBirdQrCodeDetectedEventTypeId);
|
||||
event.setParams(ParamList() << Param(doorBirdQrCodeDetectedEventDataParamTypeId, "image received"));
|
||||
emit emitEvent(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,19 @@
|
|||
"id": "9bc89937-a2ab-4e8e-af0e-a9ba41caa89b",
|
||||
"name": "doorbellPressed",
|
||||
"displayName": "Doorbell pressed"
|
||||
},
|
||||
{
|
||||
"id": "224f1be5-17d3-460d-9bb8-a25fcdf28936",
|
||||
"name": "qrCodeDetected",
|
||||
"displayName": "QR code detected",
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "c53068b9-604e-4dfc-8d23-26e8bab0233c",
|
||||
"name": "data",
|
||||
"displayName": "Data",
|
||||
"type": "QString"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ QUuid Doorbird::lightOn()
|
|||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcDoorBird) << "Error unlatching DoorBird device" << reply->error() << reply->errorString();
|
||||
qCWarning(dcDoorBird) << "Error light on" << reply->error() << reply->errorString();
|
||||
emit requestSent(requestId, false);
|
||||
return;
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ QUuid Doorbird::lightOn()
|
|||
|
||||
QUuid Doorbird::liveVideoRequest()
|
||||
{
|
||||
QNetworkRequest request(QString("http://%1/bha-api/info.cgi").arg(m_address.toString()));
|
||||
QNetworkRequest request(QString("http://%1/bha-api/video.cgi").arg(m_address.toString()));
|
||||
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||
QUuid requestId = QUuid::createUuid();
|
||||
|
|
@ -125,11 +125,11 @@ QUuid Doorbird::liveVideoRequest()
|
|||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcDoorBird) << "Error unlatching DoorBird device";
|
||||
qCWarning(dcDoorBird) << "Error live video request" << reply->error() << reply->errorString();
|
||||
emit requestSent(requestId, false);
|
||||
return;
|
||||
}
|
||||
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||
qCDebug(dcDoorBird) << "DoorBird live video request" ;
|
||||
emit requestSent(requestId, true);
|
||||
});
|
||||
return requestId;
|
||||
|
|
@ -137,7 +137,7 @@ QUuid Doorbird::liveVideoRequest()
|
|||
|
||||
QUuid Doorbird::liveImageRequest()
|
||||
{
|
||||
QNetworkRequest request(QString("http://%1/bha-api/light-on.cgi").arg(m_address.toString()));
|
||||
QNetworkRequest request(QString("http://%1/bha-api/image.cgi").arg(m_address.toString()));
|
||||
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||
QUuid requestId = QUuid::createUuid();
|
||||
|
|
@ -145,15 +145,17 @@ QUuid Doorbird::liveImageRequest()
|
|||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcDoorBird) << "Error unlatching DoorBird device" << reply->error() << reply->errorString();
|
||||
qCWarning(dcDoorBird) << "Error live image request" << reply->error() << reply->errorString();
|
||||
emit requestSent(requestId, false);
|
||||
return;
|
||||
}
|
||||
qCDebug(dcDoorBird) << "DoorBird light on:";
|
||||
emit requestSent(requestId, true);
|
||||
|
||||
QImage* image = new QImage();
|
||||
image->loadFromData(reply->readAll());
|
||||
QByteArrayList tokens = reply->readAll().split('\n');
|
||||
QImage image = QImage::fromData(tokens.last());
|
||||
//image.save("testfile");
|
||||
emit liveImageReceived(image);
|
||||
qCDebug(dcDoorBird) << "DoorBird live image request:";
|
||||
emit requestSent(requestId, true);
|
||||
});
|
||||
return requestId;
|
||||
}
|
||||
|
|
@ -172,11 +174,11 @@ QUuid Doorbird::historyImageRequest(int index)
|
|||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcDoorBird) << "Error unlatching DoorBird device";
|
||||
qCWarning(dcDoorBird) << "Error history image request" << reply->error() << reply->errorString();
|
||||
emit requestSent(requestId, false);
|
||||
return;
|
||||
}
|
||||
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||
qCDebug(dcDoorBird) << "DoorBird history image received:";
|
||||
emit requestSent(requestId, true);
|
||||
});
|
||||
return requestId;
|
||||
|
|
@ -192,11 +194,11 @@ QUuid Doorbird::liveAudioReceive()
|
|||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcDoorBird) << "Error DoorBird device";
|
||||
qCWarning(dcDoorBird) << "Error live audio receive";
|
||||
emit requestSent(requestId, false);
|
||||
return;
|
||||
}
|
||||
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||
qCDebug(dcDoorBird) << "DoorBird live audio receive";
|
||||
emit requestSent(requestId, true);
|
||||
});
|
||||
return requestId;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <QHostAddress>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QUuid>
|
||||
#include <QImage>
|
||||
|
||||
class Doorbird : public QObject
|
||||
{
|
||||
|
|
@ -92,6 +93,8 @@ signals:
|
|||
void eventReveiced(EventType eventType, bool status);
|
||||
void favoritesReceived(QList<FavoriteObject> favourites);
|
||||
|
||||
void liveImageReceived(QImage image);
|
||||
|
||||
public slots:
|
||||
void onUdpBroadcast(const QByteArray &data);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,16 +2,12 @@ include(../plugins.pri)
|
|||
|
||||
QT += network
|
||||
|
||||
LIBS += -lzbar
|
||||
|
||||
TARGET = $$qtLibraryTarget(nymea_deviceplugindoorbird)
|
||||
|
||||
SOURCES += \
|
||||
deviceplugindoorbird.cpp \
|
||||
doorbird.cpp \
|
||||
qrcodereader.cpp \
|
||||
|
||||
HEADERS += \
|
||||
deviceplugindoorbird.h \
|
||||
doorbird.h \
|
||||
qrcodereader.h \
|
||||
|
|
|
|||
|
|
@ -1,190 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* Copyright: 2013 Michael Zanetti <michael_zanetti@gmx.net> *
|
||||
* *
|
||||
* This file is part of ubuntu-authenticator *
|
||||
* *
|
||||
* This prject is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This project is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/*
|
||||
#include "qrcodereader.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QUrlQuery>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
QRCodeReader::QRCodeReader(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
connect(&m_readerThread, &QThread::started, this, &QRCodeReader::scanningChanged);
|
||||
connect(&m_readerThread, &QThread::finished, this, &QRCodeReader::scanningChanged);
|
||||
}
|
||||
|
||||
bool QRCodeReader::valid() const
|
||||
{
|
||||
return !m_type.isEmpty() && !m_text.isEmpty();
|
||||
}
|
||||
|
||||
QString QRCodeReader::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
QString QRCodeReader::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
QImage QRCodeReader::image() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
QRect QRCodeReader::scanRect() const
|
||||
{
|
||||
return m_scanRect;
|
||||
}
|
||||
|
||||
void QRCodeReader::setScanRect(const QRect &rect)
|
||||
{
|
||||
if (m_scanRect != rect) {
|
||||
m_scanRect = rect;
|
||||
emit scanRectChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool QRCodeReader::scanning() const
|
||||
{
|
||||
return m_readerThread.isRunning();
|
||||
}
|
||||
|
||||
void QRCodeReader::grab(QImage image)
|
||||
{
|
||||
m_type.clear();
|
||||
m_text.clear();
|
||||
emit validChanged();
|
||||
|
||||
if (m_scanRect.isValid()) {
|
||||
image = image.copy(m_scanRect);
|
||||
}
|
||||
|
||||
Reader *reader = new Reader;
|
||||
reader->moveToThread(&m_readerThread);
|
||||
connect(reader, SIGNAL(finished()), reader, SLOT(deleteLater()));
|
||||
connect(reader, SIGNAL(finished()), &m_readerThread, SLOT(quit()));
|
||||
connect(reader, SIGNAL(resultReady(QString, QString, QImage)), this, SLOT(handleResults(QString, QString, QImage)));
|
||||
m_readerThread.start();
|
||||
|
||||
//QMetaObject::invokeMethod(reader, "doWork", Q_ARG(QImage, img), Q_ARG(bool, false));
|
||||
}
|
||||
|
||||
void QRCodeReader::processImage(const QUrl &url)
|
||||
{
|
||||
QImage image;
|
||||
if (!image.load(url.path())) {
|
||||
qWarning() << "can't open" << url.path();
|
||||
return;
|
||||
}
|
||||
|
||||
Reader *reader = new Reader;
|
||||
reader->moveToThread(&m_readerThread);
|
||||
connect(reader, SIGNAL(finished()), reader, SLOT(deleteLater()));
|
||||
connect(reader, SIGNAL(finished()), &m_readerThread, SLOT(quit()));
|
||||
connect(reader, SIGNAL(resultReady(QString, QString, QImage)), this, SLOT(handleResults(QString, QString, QImage)));
|
||||
m_readerThread.start();
|
||||
|
||||
QMetaObject::invokeMethod(reader, "doWork", Q_ARG(QImage, image), Q_ARG(bool, false));
|
||||
}
|
||||
|
||||
void QRCodeReader::handleResults(const QString &type, const QString &text, const QImage &codeImage)
|
||||
{
|
||||
m_type = type;
|
||||
m_text = text;
|
||||
m_image = codeImage;
|
||||
m_imageUuid = QUuid::createUuid();
|
||||
emit validChanged();
|
||||
}
|
||||
|
||||
void Reader::doWork(const QImage &image, bool invert)
|
||||
{
|
||||
// Prepare image
|
||||
QImage copy = image;
|
||||
if (invert) {
|
||||
copy.invertPixels();
|
||||
}
|
||||
zbar::QZBarImage img(copy.convertToFormat(QImage::Format_RGB32));
|
||||
zbar::Image tmp = img.convert(*(long*)"Y800");
|
||||
|
||||
// create a reader
|
||||
zbar::ImageScanner scanner;
|
||||
|
||||
// configure the reader
|
||||
scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
|
||||
scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_POSITION, 1);
|
||||
scanner.set_config(zbar::ZBAR_PARTIAL, zbar::ZBAR_CFG_ENABLE, 0);
|
||||
|
||||
// scan the image for barcodes
|
||||
int n = scanner.scan(tmp);
|
||||
// qDebug() << "scanned. have" << n << "symbols";
|
||||
if (!invert && n == 0) {
|
||||
// Nothing found... try again inverted
|
||||
doWork(image, true);
|
||||
return;
|
||||
}
|
||||
|
||||
img.set_symbols(tmp.get_symbols());
|
||||
|
||||
// extract results
|
||||
for(zbar::Image::SymbolIterator symbol = img.symbol_begin(); symbol != img.symbol_end(); ++symbol) {
|
||||
|
||||
QString typeName = QString::fromStdString(symbol->get_type_name());
|
||||
QString symbolString = QString::fromStdString(symbol->get_data());
|
||||
|
||||
int x0 = 999999;
|
||||
int y0 = 999999;
|
||||
int x1 = 0;
|
||||
int y1 = 0;
|
||||
|
||||
for (int i = 0; i < symbol->get_location_size(); ++i) {
|
||||
int x = symbol->get_location_x(i);
|
||||
int y = symbol->get_location_y(i);
|
||||
qDebug() << "got point" << x << y;
|
||||
if (x < x0) x0 = x;
|
||||
if (y < y0) y0 = y;
|
||||
if (x > x1) x1 = x;
|
||||
if (y > y1) y1 = y;
|
||||
}
|
||||
|
||||
int width = x1 - x0;
|
||||
int height = y1 - y0;
|
||||
|
||||
// Workaround for zBar sometimes only giving us the first bar in a barcode.
|
||||
if (width < 10) width = img.get_width() - x0;
|
||||
if (height < 10) height = img.get_height() - y0;
|
||||
|
||||
qDebug() << "extracting code image (" << x0 << y0 << ") ("<< x1 << y1 << ")";
|
||||
QImage codeImage = image.copy(x0, y0, width, height);
|
||||
|
||||
qDebug() << "Code recognized:" << typeName << ", Text:" << symbolString;
|
||||
|
||||
emit resultReady(typeName, symbolString, codeImage);
|
||||
}
|
||||
|
||||
tmp.set_data(NULL, 0);
|
||||
img.set_data(NULL, 0);
|
||||
|
||||
emit finished();
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* Copyright: 2013 Michael Zanetti <michael_zanetti@gmx.net> *
|
||||
* *
|
||||
* This file is part of tagger *
|
||||
* *
|
||||
* This prject is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This project is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/*
|
||||
#ifndef QRCODEREADER_H
|
||||
#define QRCODEREADER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QUuid>
|
||||
#include <QImage>
|
||||
|
||||
class QRCodeReader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
|
||||
Q_PROPERTY(QString type READ type NOTIFY validChanged)
|
||||
Q_PROPERTY(QString text READ text NOTIFY validChanged)
|
||||
Q_PROPERTY(QImage image READ image NOTIFY validChanged)
|
||||
Q_PROPERTY(QString imageSource READ imageSource NOTIFY validChanged)
|
||||
Q_PROPERTY(QRect scanRect READ scanRect WRITE setScanRect NOTIFY scanRectChanged)
|
||||
Q_PROPERTY(bool scanning READ scanning NOTIFY scanningChanged)
|
||||
|
||||
public:
|
||||
explicit QRCodeReader(QObject *parent = nullptr);
|
||||
|
||||
bool valid() const;
|
||||
QString type() const;
|
||||
QString text() const;
|
||||
QImage image() const;
|
||||
QString imageSource() const;
|
||||
QRect scanRect() const;
|
||||
void setScanRect(const QRect &rect);
|
||||
bool scanning() const;
|
||||
|
||||
|
||||
public slots:
|
||||
void grab(QImage image);
|
||||
void processImage(const QUrl &url);
|
||||
|
||||
signals:
|
||||
void validChanged();
|
||||
void scanRectChanged();
|
||||
void scanningChanged();
|
||||
|
||||
private slots:
|
||||
void handleResults(const QString &type, const QString &text, const QImage &codeImage);
|
||||
|
||||
private:
|
||||
QString m_type;
|
||||
QString m_text;
|
||||
QImage m_image;
|
||||
QUuid m_imageUuid;
|
||||
QRect m_scanRect;
|
||||
|
||||
QThread m_readerThread;
|
||||
};
|
||||
|
||||
class Reader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void doWork(const QImage &image, bool invert);
|
||||
|
||||
signals:
|
||||
void resultReady(const QString &type, const QString &text, const QImage &codeImage);
|
||||
void finished();
|
||||
};
|
||||
|
||||
#endif // QRCODEREADER_H
|
||||
*/
|
||||
Loading…
Reference in New Issue