Merge pull request #207 from ftylitak/qzxingfilter-orientation-support

QZXingFilter orientation support
This commit is contained in:
Nikos Ftylitakis 2021-08-12 16:12:17 +03:00 committed by GitHub
commit 2fd4dd60c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -85,6 +85,7 @@ ApplicationWindow
QZXingFilter
{
id: zxingFilter
orientation: videoOutput.orientation
captureRect: {
// setup bindings
videoOutput.contentRect;

View File

@ -43,6 +43,7 @@ QZXingFilter::QZXingFilter(QObject *parent)
: QAbstractVideoFilter(parent)
, decoder(QZXing::DecoderFormat_QR_CODE)
, decoding(false)
, orientation_(0)
{
/// Connecting signals to handlers that will send signals to QML
connect(&decoder, &QZXing::decodingStarted,
@ -69,6 +70,21 @@ void QZXingFilter::handleDecodingFinished(bool succeeded)
emit isDecodingChanged();
}
void QZXingFilter::setOrientation(int orientation)
{
if (orientation_ == orientation) {
return;
}
orientation_ = orientation;
emit orientationChanged(orientation_);
}
int QZXingFilter::orientation() const
{
return orientation_;
}
QVideoFilterRunnable * QZXingFilter::createFilterRunnable()
{
return new QZXingFilterRunnable(this);
@ -372,7 +388,19 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
//QZXingImageProvider::getInstance()->storeImage(image);
decode(*image_ptr);
int orientation = filter ? filter->orientation() : 0;
if (!orientation) {
decode(*image_ptr);
} else {
QTransform transformation;
transformation.translate(image_ptr->rect().center().x(), image_ptr->rect().center().y());
transformation.rotate(-orientation);
QImage translatedImage = image_ptr->transformed(transformation);
decode(translatedImage);
}
delete image_ptr;
}

View File

@ -75,16 +75,20 @@ class QZXingFilter : public QAbstractVideoFilter
Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged)
Q_PROPERTY(QZXing* decoder READ getDecoder)
Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
signals:
void isDecodingChanged();
void decodingFinished(bool succeeded, int decodeTime);
void decodingStarted();
void captureRectChanged();
void orientationChanged(int orientation);
private slots:
void handleDecodingStarted();
void handleDecodingFinished(bool succeeded);
void setOrientation(int orientation);
int orientation() const;
private: /// Attributes
QZXing decoder;
@ -93,6 +97,7 @@ class QZXingFilter : public QAbstractVideoFilter
SimpleVideoFrame frame;
QFuture<void> processThread;
int orientation_;
public: /// Methods
explicit QZXingFilter(QObject *parent = 0);