GithubHelp home page GithubHelp logo

scythestudio / scodes Goto Github PK

View Code? Open in Web Editor NEW
100.0 2.0 33.0 3.14 MB

This project is Qt & Qml wrapper for ZXing-C++ Library that is used for decoding 1D and 2D barcodes.

Home Page: https://scythe-studio.com/

License: Apache License 2.0

C++ 59.17% QMake 20.00% C 18.08% CMake 2.75%
qml zxing-cpp zxing qt

scodes's Introduction

SCodes

SCodes

This project is Qt & Qml wrapper for ZXing-C++ Library that is used for decoding and generating 1D and 2D barcodes. This particular C++ ZXing port is one of the most recent C++ versions of popular ZXing library using modern compilers.

Thanks to SCodes you can start scanning barcodes in few steps. We used Qt 5.15.2 and Qt 6.3.0 to built wrapper and example applications, but it's compatible with older Qt versions as well.

Implementation of same method for both Qt version does not seems possible(check why). We have ported the SCodes wrapper to Qt6 by following the multimedia changes.


Scythe Studio

Built with Qt


Supported Formats

There are plenty of supported formats and we constantly work on adding new.

Supported 1D Formats

Format Supports scanning Supports generating
UPC-A ✔️ ✔️
UPC-E ✔️ ✔️
EAN-8 ✔️ ✔️
EAN-13 ✔️ ✔️
DataBar ✔️
DataBar Expanded
Code 39 ✔️ ✔️
Code 93 ✔️ ✔️
Code 128 ✔️ ✔️
Codabar ✔️ ✔️
ITF ✔️

Supported 2D Formats

Format Supports scanning Supports generating
QR Code ✔️ ✔️
DataMatrix ✔️ ✔️
Aztec ✔️ ✔️
PDF417 ✔️ ✔️
MaxiCode

How to use wrapper?

SCodes Scanner PreviewSCodes Generator Preview

Using

Feel free to read "How to scan barcodes in Qt Qml application" blog post if you are interested in the details behind scanning mechanism. Also you can try out the QmlReaderExample in order to see how it is working.

SCodes supports generating barcodes as well. It is covered in "How to generate barcode in Qt Qml" application blog post. Also you can try out the QmlGeneratorExample in order to see how it is working.

Above blog posts contains step by step tutorial on how to do that for Qt5 version. For Qt6 (see here).

qmake

All you need to do is to follow these steps.

  1. Add SCodes as submodule, by typing git submodule add [email protected]:scytheStudio/SCodes.git
  2. Update submodule git submodule update --recursive --init (you can also put wrapper files to your project manually without adding submodule)
  3. Add include(scodes/src/SCodes.pri) to your .pro file
  4. If you want to use barcode reader functionality you need to register SBarcodeFilter class for Qt5 or SBarcodeScanner class for Qt6. For both version, separate them with if directive to register as we did in barcode reader example(how to register reader class). As for barcode generator functionality you just need to register SBarcodeGenerator class(how to register generator class).
  5. Import SCodes in your Qml file import com.scythestudio.scodes 1.0
  6. Import multimedia module import QtMultimedia 5.15 for Qt5 or import QtMultimedia for Qt6.
  7. If build fails, try to add CONFIG += c++17 to your .pro file
  8. You are done. Get inspired by Qt5 QML Barcode Reader demo or Qt6 QML Barcode Reader demo to test wrapper.

CMake

  1. Add SCodes as submodule, by typing git submodule add [email protected]:scythestudio/scodes.git

  2. Update submodule git submodule update --recursive --init (you can also put wrapper files to your project manually without adding submodule)

  3. Add to your project SCodes library

        add_subdirectory(SCodes)
  4. Link SCodes library to your library or executable.

        target_link_libraries(${PROJECT_NAME} PUBLIC SCodes)
  5. Import SCodes in your Qml file

        import com.scythestudio.scodes 1.0
  6. You are done. Get inspired by QML Barcode Reader demo to test wrapper.

How to do

Registering the barcode reader classes with if directive:

    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        qmlRegisterType<SBarcodeFilter>("com.scythestudio.scodes", 1, 0, "SBarcodeScanner");
    #else
        qmlRegisterType<SBarcodeScanner>("com.scythestudio.scodes", 1, 0, "SBarcodeScanner");
    #endif

Registering the barcode generator class with associated enum:

    qmlRegisterType<SBarcodeGenerator>("com.scythestudio.scodes", 1, 0, "SBarcodeGenerator");
    qmlRegisterUncreatableMetaObject(SCodes::staticMetaObject, "com.scythestudio.scodes", 1, 0, "SCodes", "Error: only enums");

Implementation details in Qt6

Qt's multimedia library has major changes. The most importants are, changes in QML VideoOutput, absence of QVideoFilterRunnable and QAbstractVideoFilter classes in Qt6.

SCodes library is using SBarcodeFilter class for Qt5 and SBarcodesScanner class for Qt6 version.

If you want to read more about implementation details of the library in Qt6 read the document: Implementation Details in Qt6

Trying various formats

SBarcodeFilter is a class that you need to use for scanning case. By default it scans only specific basic formats of code (Code 39, Code 93, Code 128, QR Code and DataMatrix.). The goal of that is to limit number of possible formats and improve performance.

To specify formats that should be accepted by the SBarcodeFilter instance, you need to set it's format property accordingly. This property allows setting multiple enum values as it's for flags. Add the following to your SBarcodeFilter item in Qml code:

Component.onCompleted: {
    barcodeFilter.format = SCodes.OneDCodes
}

See the enumeration values that represent supported formats in SBarcodeFormat.h To accept all supported formats use SCodes.Any.

Note

Both build systems have their examples located in same directory. All you need to do is to just open proper file(CMakeLists.txt or *.pro file) for different build system to be used.

The examples tested on below kits:

Qt5.15.2 or less,

PROJECT BUILD SYSTEM WINDOWS-MinGW WINDOWS-MSVC LINUX-GCC ANDROID
QmlBarcodeReader qmake ✔️ ✔️ ✔️ ✔️
QmlBarcodeGenerator qmake ✔️ ✔️ ✔️ ✔️
QmlBarcodeReader CMake ✔️ ✔️ ✔️
QmlBarcodeGenerator CMake ✔️ ✔️ ✔️

Qt6.3.0,

PROJECT BUILD SYSTEM WINDOWS-MinGW WINDOWS-MSVC LINUX-GCC ANDROID
QmlBarcodeReader qmake ✔️ ✔️ ✔️ ✔️
QmlBarcodeGenerator qmake ✔️ ✔️ ✔️ ✔️
QmlBarcodeReader CMake ✔️ ✔️ ✔️ ✔️
QmlBarcodeGenerator CMake ✔️ ✔️ ✔️ ✔️

Please ensure that proper Java & NDK version installed on your system. This examples tested w/ Java 11 and 22.1.7171670 Android NDK version.

About Scythe Studio

We are a group of Qt and C++ enthusiasts whose goal is to address growing demand for cross-platform Qt development services. Thanks to our expertise in Qt Qml development, quality of deliveries and proven track of projects developed for companies from various industries we have been awarded the title of an official Qt Service Partner.

The company offers broad spectrum of services for the clients who wish to bring their ideas to life. We have extensive and practical knowledge about various Qt modules and other technologies allowing to create high quality product in a cost effective approach. If you want to see what Scythe Studio is is capable of and what services we provide, check out this link.

Follow us

Check out those links if you want to see Scythe Studio in action and follow the newest trends saying about Qt Qml development.

scodes's People

Contributors

bartoszskorka avatar endrii avatar fibur avatar j-kies avatar kosadev avatar mannkin avatar marcelpetrick avatar omrdk avatar omrfdk avatar radkoder avatar talamaki avatar vvozny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

scodes's Issues

Multi-Threading: Mistake causes freeze

void SBarcodeScanner::handleFrameCaptured(const QVideoFrame& frame)
{
if (m_processing) {
emit process(m_decoder.videoFrameToImage(frame, captureRect().toRect()));
if (m_videoSink) {
m_videoSink->setVideoFrame(frame);
}
}
pauseProcessing();
}

Note that pauseProcessing() is called on the main thread while the Worker thread is processing an image and afterwards calls continueProcessing().
So I guess the library stops working because: continueProcessing() is called on Worker thread before the pauseProcessing() is called on main thread for the next camera frame.

Have fun 😥

Error android compiler

when i compile get the error: SCodes/src/zxing-cpp/core/src/Result.cpp', needed by 'armeabi-v7a/Result.o'. Stop.

Documentation in README uses undefined values

Hey guys,

first of all: awesome tool you have created there!

Unfortunately there is a minor issue with your README file. You explain that to try various formats one just would have to add the following code:

Component.onCompleted: { barcodeFilter.format = SCodes.OneDCodes }

That may be correct but the namespace SCodes has not been exposed to QML anywhere. I've also checked the example QmlBarcodeReader and did not find any registration code for that namespace either.

The only thing one has to do to make that example work is to add the following lines:

qmlRegisterUncreatableMetaObject( SCodes::staticMetaObject, // meta object created by Q_NAMESPACE macro "SBarcodeFilter.scodes", // import statement (can be any string) 1, 0, // major and minor version of the import "SCodes", // name in QML (does not have to match C++ name) "Error: only enums" // error in case someone tries to create a MyNamespace object );

The name of the import statement is just an example of course and can be changed to your needs accordingly.

Memory leak with Qt5.12

Hi,
I am trying your wrapper with Qt5.12, and encountered a memory leak. This is due to imageFromVideoFrame() in SBarcodeDecoder.cpp (Line 188)
There is memory allocated for the frame to be copied, but QImage do not take ownership of the memory, so it is never released.
QImage provides a handler mecanism, intended to free the memory when the last intance of QImage using this memory is destroyed.
You need to create the handler to cleanup the memory, and provide it to the QImage when creating it, with the pointer to the memory.
Also, the memory must be allocated only when it is need, i.e. when imageFormat == QImage::Format_Invalid
Here is the modified code :

void imageCleanupHandler(void *info)
{
    delete[] (uchar*)info;
}

QImage SBarcodeDecoder::imageFromVideoFrame(const QVideoFrame &videoFrame)
{
    QImage::Format imageFormat = videoFrame.imageFormatFromPixelFormat(videoFrame.pixelFormat());
    if(imageFormat == QImage::Format_Invalid){
        uchar* ARGB32Bits = new uchar[(videoFrame.width() * videoFrame.height()) * 4];
        switch(videoFrame.pixelFormat()){
            case QVideoFrame::Format_YUYV: qt_convert_YUYV_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_NV12: qt_convert_NV12_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_YUV420P: qt_convert_YUV420P_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_YV12: qt_convert_YV12_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_AYUV444: qt_convert_AYUV444_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_YUV444: qt_convert_YUV444_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_UYVY: qt_convert_UYVY_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_NV21: qt_convert_NV21_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_BGRA32: qt_convert_BGRA32_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_BGR24: qt_convert_BGR24_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_BGR565: qt_convert_BGR565_to_ARGB32(videoFrame, ARGB32Bits); break;
            case QVideoFrame::Format_BGR555: qt_convert_BGR555_to_ARGB32(videoFrame, ARGB32Bits); break;
            default: break;
        }

        return QImage(ARGB32Bits,
                      videoFrame.width(),
                      videoFrame.height(),
                      QImage::Format_ARGB32,
                      imageCleanupHandler,
                      ARGB32Bits);
    }

    return QImage(videoFrame.bits(),
                  videoFrame.width(),
                  videoFrame.height(),
                  imageFormat);
}

These modifications solve the memory leak problem for me.
Sorry I don't have the time to create a proper PR, but I thought it might be usefull for others.

Bug with scan animation

I use the example of "QmlBarcodeReader" with Qt6 version 6.6.2, java 11.0.15.1 and NDK 25.2.9519653. The barcode scan works but the scan animation stays at the top of the rectangle and only moves a few millimeters.
20240229_084632 1

iOS

Is this working on iOS ?
if yes can you add examples on how to use it on iOS ?

Thanks

Android white screen

HI, i compiled on Android but i see a white screen like the camera closed. Is there some work in progress or some my mistake? I cloned the zxing-cpp and compiled the example with Qt6.

Join forces with upstream zxing-cpp?

Hi, I just noticed your project as I saw it mentioned in https://github.com/zxing/zxing. After realizing that it is based on "our" c++ fork, I was curious what you offered on top of my qt-example-code. I noticed that you copied part of it (thereby "accidentally" infringing on my copyright, by the way ;)) but opted to not use the QVideoFrame based ReadBarcode implementation and instead went for a video-frame -> QImage conversion way, which is definitively a bad idea in terms of performance and seems to have caused other issues (#13), too. May I ask why?

I'd like to encourage you to take part in this discussion and see if we can centralize the efforts of providing a good zxing experience to more people. What was missing that made you come up with your wrapper?

Besides that, you might want to update your build dependency to our latest 1.3 release (from today).

Compilation fails with Qt 5.12.9

There seems to be a missing compiler directive in SBarcodesFormat.h.

#ifndef SBARCODEFORMAT_H
#define SBARCODEFORMAT_H

#include <qqml.h>
#include "BarcodeFormat.h"

namespace SCodes {
    Q_NAMESPACE
    QML_ELEMENT

The directive QML_ELEMENT has been introduced in Qt 5.15. So this would not work using any version lower than that. In other files this directive has been embraced by a

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
        QML_ELEMENT
#endif

Best regards

Desktop Support and QR Code Generation

I have two feature suggestions:

  • The scanner works well on mobile, but not on macOS / Win desktop.
  • It would be nice to also be able to create QR codes. (text-to-barcode image generation)

README.md instruction #1 - error running command

Hello,

First of all, congrats and thanks for sharing this useful library.
I am following the README.md instructions on how to use the submodule in a project. But in the 1st step, I got an error:


$ git submodule add [email protected]:scythestudio/scodes.git
Cloning into '/home/rgb/QtProjects/minibrowser/scodes'...
[email protected]: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:scythestudio/scodes.git' into submodule path '/home/rgb/QtProjects/minibrowser/scodes' failed

So I just replaced the repo location by the one here on github:
$ git submodule add https://github.com/scytheStudio/SCodes.git

It worked just fine.

Now, I don't know if I did something wrong or if the README file's instruction #1 must be updated.
Just trying to keep you guys informed.

Regards

Button Scan again do not work

I use the example QmlBarcodeReader with Qt6. The application run and a qrCode is detected.

After barcode recogniztion I click on the button "Scan again" the overlay is disabled and the input mask with the video appear.

After scanning a new barcode nothing happens - no recognition, nothing.

Autofocus not working on iphone 13 (ios)

I built the QmlBarcodeReader in QT 6.2.4 for ios. The application Opens on the iphone 13 but it not able to detect any bar code or QR code as it is not auto focusing.
Thanks

Image in the center of QR code

Allow setting an image in the center of the generated QR code. For example, in Telegram Desktop:

imagen

Ideally, this should support any Item-based object (for example, to be able set a lottie animation or a button, progress bar, etc.)

Qt/QML 6 version

I am trying to recompile for Qt/QML 6 and it does not compile as other packages have been removed from Qt 6, like Andorid Extras.

Any chance a porting to Qt 6?

Android with Qt 6.4.3 ERror

the example QML Barcode reader crashed

E EGL_emulation: eglQueryContext 32c0 EGL_BAD_ATTRIBUTE
E EGL_emulation: tid 1898: eglQueryContext(2160): error 0x3004 (EGL_BAD_ATTRIBUTE)
W libQmlBarcodeReader_x86_64.so: Qt has caught an exception thrown from an event handler. Throwing
W libQmlBarcodeReader_x86_64.so: exceptions from an event handler is not supported in Qt.
W libQmlBarcodeReader_x86_64.so: You must not let any exception whatsoever propagate through Qt code.
E libc++abi: terminating with uncaught exception of type std::out_of_range: Requested row is outside the image
F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 1871 (QThread), pid 1791 (mlbarcodereader)

App Crashes on "No camera detected" Error

Without a camera on the Desktop, the code will try to access settings.at(0) but since there are no cameras, that index is invalid

on SBarcodeScanner

void SBarcodeScanner::initCam() {
    camera = new QCamera(this);

    const auto settings = camera->cameraDevice().videoFormats();

#ifdef Q_OS_ANDROID
    int i = camera->cameraDevice().videoFormats().size() - 1;
#else
    int i = 0;
#endif

    const auto s = settings.at(i); // Crash Point

    // ...
}

image

Easy workaround:

void SBarcodeScanner::initCam() {
    camera = new QCamera(this);

    if(camera->error())
    {
        qDebug() << "[SCodes] initCam() Failed: " << camera->errorString();
        return;
    }

    const auto settings = camera->cameraDevice().videoFormats();

   // ...
}

Android app QmlBarcodeReader crashes after 2 secs

Output Error in Debug Mode (build with Qt 6.5.0 armeabi-v7a Kit and latest SCodes - software, on Desktop Qt Kit everything is ok)

isHandlerType=false this: DecorView@be48b76[QtActivity]
I ViewRootImpl@284cb5f[QtActivity]: ViewPostIme pointer 1
I MSHandlerLifeCycle: isMultiSplitHandlerRequested: windowingMode=1 isFullscreen=true isPopOver=false isHidden=false skipActivityType=false isHandlerType=false this: DecorView@be48b76[QtActivity]
W Qt A11Y : AccessibilityEvent with empty description
W libQmlBarcodeReader_armeabi-v7a.so: Qt has caught an exception thrown from an event handler. Throwing
W libQmlBarcodeReader_armeabi-v7a.so: exceptions from an event handler is not supported in Qt.
W libQmlBarcodeReader_armeabi-v7a.so: You must not let any exception whatsoever propagate through Qt code.
F libc : /buildbot/src/android/ndk-r25-release/toolchain/llvm-project/libcxx/../../../toolchain/llvm-project/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type std::out_of_range: Requested row is outside the image" failed
12:11:54:

"com.scythestudio.qmlbarcodereader" beendet.
12:11:54: Das Debuggen von "-qmljsdebugger=port:57142,block,services:DebugMessages,QmlDebugger,V8Debugger,QmlInspector,DebugTranslation" wurde beendet.

Can you please fix that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.