Building Command-line Barcode and QR Code Reader in C++

About Dynamsoft C++ Barcode and QR Code Reader SDK

SDK Download

v9.0

SDK License

char errorBuf[512];
DBR_InitLicense("LICENSE-KEY", errorBuf, 512);
void* barcodeReader = DBR_CreateInstance();
char errorBuf[512];
dynamsoft::dbr::CBarcodeReader::InitLicense("LICENSE-KEY", errorBuf, 512);
CBarcodeReader* reader = new CBarcodeReader();

A Command-line C++ Barcode and QR Code Reader for Multiple Platforms

MESSAGE( STATUS "CPU architecture ${CMAKE_SYSTEM_PROCESSOR}" )
if(WINDOWS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
link_directories("${PROJECT_SOURCE_DIR}/platforms/win/bin/")
else()
link_directories("${PROJECT_SOURCE_DIR}/platforms/win/lib/")
endif()
elseif(LINUX)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/platforms/linux/" )
link_directories("${PROJECT_SOURCE_DIR}/platforms/linux/")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR ARM32_BUILD)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/platforms/arm32/" )
link_directories("${PROJECT_SOURCE_DIR}/platforms/arm32/")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/platforms/aarch64/" )
link_directories("${PROJECT_SOURCE_DIR}/platforms/aarch64/")
endif()
elseif(MACOS)
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/platforms/macos/" )
link_directories("${PROJECT_SOURCE_DIR}/platforms/macos/")
endif()
include_directories("${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include/")
language: cpp

jobs:
include:
- os: linux
arch: arm64
env: OS=arm64_linux
- os: linux
arch: amd64
env: OS=amd64_linux
- os: windows
arch: amd64
env: OS=windows
- os: osx
arch: amd64
env: OS=osx
- os: linux
arch: arm64
env: OS=arm32_linux
before_install:
- sudo dpkg --add-architecture armhf
- sudo apt-get update
- sudo apt-get install crossbuild-essential-armhf libc6:armhf libstdc++6:armhf

branches:
only:
- main

script:
- mkdir build
- cd build
- if [[ ${TRAVIS_OS_NAME} == "windows" ]]; then
cmake -DCMAKE_GENERATOR_PLATFORM=x64 ..;
else
if [ $OS == "arm32_linux" ]; then
export CC=arm-linux-gnueabihf-gcc;
export CXX=arm-linux-gnueabihf-g++;
export AR=arm-linux-gnueabihf-ar;
cmake -DARM32_BUILD=TRUE ..;
else
cmake ..;
fi
fi
- cmake --build . --config release
  1. Include the header files:
#include "DynamsoftBarcodeReader.h"
#include "BarcodeReaderConfig.h"
char errorBuf[512];
DBR_InitLicense("LICENSE-KEY", errorBuf, 512);
void* barcodeReader = DBR_CreateInstance();
char errorBuf[512];
dynamsoft::dbr::CBarcodeReader::InitLicense("LICENSE-KEY", errorBuf, 512);
CBarcodeReader* reader = new CBarcodeReader();
int errorCode = DBR_DecodeFile(barcodeReader, "image-file", "");
int errorCode = reader->DecodeFile("image-file", "");
TextResultArray* pResults;
DBR_GetAllTextResults(barcodeReader, &pResults);
TextResultArray* pResults;
reader->GetAllTextResults(&pResults);
for (int index = 0; index < pResults->resultsCount; index++)
{
printf("Barcode %d:\n", index + 1);
printf(" Type: %s\n", pResults->results[index]->barcodeFormatString);
printf(" Text: %s\n", pResults->results[index]->barcodeText);
}

Source Code

Build and Run

mkdir build
cd build
cmake ..
cmake --build . --config release
./BarcodeReader [image-file] [optional: license-file] [optional: template-file]

--

--

--

Manager of Dynamsoft Open Source Projects | Tech Lover

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xiao Ling

Xiao Ling

Manager of Dynamsoft Open Source Projects | Tech Lover

More from Medium

Invalid use of Nonstatic Member Function

Why does malloc initialize values to zero in GCC?

C++ Placement New

C for Beginners (Part Nine)