Page 1 of 1

How to develop a program that recognizes QR codes using zxing-cpp?

Posted: 2024-07-21 14:40
by cocoa
I want to create a program that recognizes QR codes using zxing-cpp in luckfox Pico Max.
I built it by adding a package from Buildroot, but I'm not sure how to use it.
It would be good if anyone could tell me what to do to develop a program using zxing-cpp.

Re: How to develop a program that recognizes QR codes using zxing-cpp?

Posted: 2024-07-22 6:21
by cocoa
I compiled and ran the QR code recognition program using zxing-cpp 2.2.1 through the following procedures.

ENV : WSL Ubuntu 22.04

~/luckfox/dev$ mkdir barcode
~/luckfox/dev$ cd barcode
~/luckfox/dev/barcode$ git clone https://github.com/zxing-cpp/zxing-cpp.git
~/luckfox/dev/barcode$ cd zxing-cpp

~/luckfox/dev/barcode/zxing-cpp$ nano luckfox_toolchain.cmake

Code: Select all

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER /home/smart/luckfox/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc)
set(CMAKE_CXX_COMPILER /home/smart/luckfox/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-g++)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_FIND_ROOT_PATH /home/smart/luckfox/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
~/luckfox/dev/barcode/zxing-cpp$ nano CMakeLists.txt

Code: Select all

include(luckfox_toolchain.cmake)

cmake_minimum_required(VERSION 3.15)

project(ZXing)

option (ZXING_READERS "Build with reader support (decoders)" ON)
set    (ZXING_WRITERS "ON" CACHE STRING "Build with old and/or new writer (encoder) backend (OFF/ON/OLD/NEW/BOTH)")
option (ZXING_USE_BUNDLED_ZINT "Use the bundled libzint for barcode creation/writing" ON)
option (ZXING_C_API "Build the C-API" OFF)
option (ZXING_EXPERIMENTAL_API "Build with experimental API" OFF)
option (ZXING_EXAMPLES "Build the example barcode reader/writer applications" ON)
option (ZXING_BLACKBOX_TESTS "Build the black box reader/writer tests" OFF)
option (ZXING_UNIT_TESTS "Build the unit tests (don't enable for production builds)" OFF)
option (ZXING_PYTHON_MODULE "Build the python module" OFF)
set    (ZXING_DEPENDENCIES "AUTO" CACHE STRING "Fetch from github or use locally installed (AUTO/GITHUB/LOCAL)")



if (WIN32)
    option (BUILD_SHARED_LIBS "Build and link as shared library" OFF)
else()
    option (BUILD_SHARED_LIBS "Build and link as shared library" ON)
endif()

if (MSVC)
    add_definitions (-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS)
    option (ZXING_LINK_CPP_STATICALLY "MSVC only, link standard library statically (/MT and /MTd)" OFF)
    if (LINK_CPP_STATICALLY OR ZXING_LINK_CPP_STATICALLY)
        set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    endif()
endif()

if (NOT CMAKE_BUILD_TYPE)
    set (DEFAULT_BUILD_TYPE "Release")
    message (STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
    set (CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
    set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()


# provide backward compatibility for deprecated BUILD_... options
if (DEFINED BUILD_READERS)
    set (ZXING_READERS ${BUILD_READERS})
endif()
if (DEFINED BUILD_WRITERS)
    set (ZXING_WRITERS ${BUILD_WRITERS})
endif()
if (DEFINED BUILD_EXAMPLES)
    message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
    set (ZXING_EXAMPLES ${BUILD_EXAMPLES})
endif()
if (DEFINED BUILD_PYTHON_MODULE)
    message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
    set (ZXING_PYTHON_MODULE ${BUILD_PYTHON_MODULE})
endif()
if (DEFINED BUILD_DEPENDENCIES)
    message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
    set (ZXING_DEPENDENCIES ${BUILD_DEPENDENCIES})
endif()

if (NOT (ZXING_READERS OR ZXING_WRITERS))
    message(FATAL_ERROR "At least one of ZXING_READERS/ZXING_WRITERS must be enabled.")
endif()

set(ZXING_WRITERS_LIST OFF ON OLD NEW BOTH)
set_property(CACHE ZXING_WRITERS PROPERTY STRINGS ${ZXING_WRITERS_LIST})
if(NOT ZXING_WRITERS IN_LIST ZXING_WRITERS_LIST)
    message(FATAL_ERROR "ZXING_WRITERS must be one of ${ZXING_WRITERS_LIST}")
endif()

set(ZXING_DEPENDENCIES_LIST AUTO GITHUB LOCAL)
set_property(CACHE ZXING_DEPENDENCIES PROPERTY STRINGS ${ZXING_DEPENDENCIES_LIST})
if(NOT ZXING_DEPENDENCIES IN_LIST ZXING_DEPENDENCIES_LIST)
    message(FATAL_ERROR "ZXING_DEPENDENCIES must be one of ${ZXING_DEPENDENCIES_LIST}")
endif()

if (NOT DEFINED CMAKE_CXX_STANDARD)
    set (CMAKE_CXX_STANDARD 17)
endif()
if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
    set (CMAKE_CXX_EXTENSIONS OFF)
endif()

add_subdirectory (core)

enable_testing()

include(zxing.cmake)

if (ZXING_EXAMPLES)
    add_subdirectory (example)
endif()
if (ZXING_BLACKBOX_TESTS)
    add_subdirectory (test/blackbox)
endif()
if (ZXING_UNIT_TESTS)
    add_subdirectory (test/unit)
endif()
if (ZXING_PYTHON_MODULE)
    add_subdirectory (wrappers/python)
endif()
if (ZXING_C_API)
    add_subdirectory (wrappers/c)
endif()
As shown in the code above, "include(luckfox_toolchain.cmake)" was added to the first part of CMakeLists.txt.

~/luckfox/dev/barcode/zxing-cpp$ mkdir build
~/luckfox/dev/barcode/zxing-cpp$ cd build
~/luckfox/dev/barcode/zxing-cpp/build$ cmake ..

~/luckfox/dev/barcode/zxing-cpp/build$ make help
~/luckfox/dev/barcode/zxing-cpp/build$ make ZXing
~/luckfox/dev/barcode/zxing-cpp/build$ make ZXingReader
~/luckfox/dev/barcode/zxing-cpp/build$ cd core
~/luckfox/dev/barcode/zxing-cpp/build/core$ scp libZXing.so.2.2.1 root@172.32.0.93:/root
~/luckfox/dev/barcode/zxing-cpp/build/core$ cd ..
~/luckfox/dev/barcode/zxing-cpp/build$ cd example
~/luckfox/dev/barcode/zxing-cpp/build/example$ scp ZXingReader root@172.32.0.93:/root

Execute the following command in LuckFox Pico Max.

[root@luckfox root]$ ln -s libZXing.so.2.2.1 libZXing.so.3
[root@luckfox root]$ ln -s libZXing.so.3 libZXing.so
[root@luckfox root]$ mv lib* /usr/lib

Recognize barcodes as follows:

[root@luckfox root]$ ./ZXingReader opencv_cap1.bmp

Re: How to develop a program that recognizes QR codes using zxing-cpp?

Posted: 2025-01-26 3:49
by wcliew
Hi,
I’d like to do the same. Is the codes above working as it intended? How about grabbing a frame from camera directly?