Skip to content

Commit

Permalink
Added an example of reading barcodes from image files.
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed May 20, 2024
1 parent c4345ef commit 80dbdfe
Show file tree
Hide file tree
Showing 4 changed files with 577 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ jobs:
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -S ${{ github.workspace }}/examples/9.x/command_line -B ${{github.workspace}}/examples/9.x/command_line/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
- name: Build command line program
# Build your program with the given configuration
run: |
cmake --build ${{github.workspace}}/examples/9.x/command_line/build --config ${{env.BUILD_TYPE}}
# cmake --install ${{github.workspace}}/examples/9.x/command_line/build
- name: Test
working-directory: ${{github.workspace}}/examples/9.x/command_line/dist
run: ./main ../../../../images/AllSupportedBarcodeTypes.png ../../../../license-key.txt
# - name: Test
# working-directory: ${{github.workspace}}/examples/9.x/command_line/dist
# run: ./main ../../../../images/AllSupportedBarcodeTypes.png ../../../../license-key.txt

# - name: Archive Release
# uses: thedoctor0/zip-release@main
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ This repository contains examples demonstrating how to utilize the **Dynamsoft B
DBR_InitLicense(license, errorMsgBuffer, 512);
```

- OpenCV Installation
1. Download [OpenCV](https://opencv.org/releases/)
2. Configure the environment variable `OpenCV_DIR` to the path of the OpenCV installation directory.
3. Add the following lines to the `CMakeLists.txt` file:

```cmake
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
```
## Supported Platforms
- Windows x64
- Linux x64/ARM64/ARM32
Expand Down Expand Up @@ -92,10 +104,17 @@ This repository contains examples demonstrating how to utilize the **Dynamsoft B
./main [image-file] [optional: license-file] [optional: template-file]
```
![Raspberry Pi Barcode Reader](https://www.dynamsoft.com/codepool/img/2016/03/rpi_dbr_result.png)
- [Barcode Image File](./examples/9.x/opencv_file)
```bash
./main
```
![Read barcodes from an image file](https://www.dynamsoft.com/codepool/img/2024/05/cpp-barcode-reader-opencv.jpg)
## Screenshots
![Raspberry Pi Barcode Reader](https://www.dynamsoft.com/codepool/img/2016/03/rpi_dbr_result.png)
## Blog
- [CMake: Build C++ Project for Windows, Linux and macOS](https://www.dynamsoft.com/codepool/cmake-cc-windows-linux-macos.html)
Expand Down
111 changes: 111 additions & 0 deletions examples/9.x/opencv_file/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
cmake_minimum_required (VERSION 3.8)
project (main)
MESSAGE( STATUS "PROJECT_NAME: " ${PROJECT_NAME} )
find_package(OpenCV REQUIRED)
option(ARM32_BUILD "Build for ARM32" OFF)

# Check ../../../platforms
if (CMAKE_HOST_WIN32)
set(WINDOWS 1)
elseif(CMAKE_HOST_APPLE)
set(MACOS 1)
elseif(CMAKE_HOST_UNIX)
set(LINUX 1)
endif()

# Check compiler architecture
if(CMAKE_CL_64)
MESSAGE( STATUS ">>>>>>>> 64-bit")
else()
MESSAGE( STATUS ">>>>>>>> 32-bit")
endif()

# Check compilers
MESSAGE( STATUS ">>>>>>>> ${CMAKE_CXX_COMPILER_ID}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
MESSAGE( STATUS "Using Clang" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
MESSAGE( STATUS "Using GNU" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
MESSAGE( STATUS "Using Intel" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
MESSAGE( STATUS "Using MSVC" )
endif()

# Set RPATH
if(CMAKE_HOST_UNIX)
if(CMAKE_HOST_APPLE)
SET(CMAKE_CXX_FLAGS "-std=c++11 -O3 -Wl,-rpath,@loader_path")
SET(CMAKE_INSTALL_RPATH "@loader_path")
else()
SET(CMAKE_CXX_FLAGS "-std=c++11 -O3 -Wl,-rpath=$ORIGIN")
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

# Add search path for include and lib files
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/")

# Add the executable
add_executable(${PROJECT_NAME} main.cxx)
if(WINDOWS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries (${PROJECT_NAME} "DynamsoftBarcodeReaderx64" ${OpenCV_LIBS})
else()
if(CMAKE_CL_64)
target_link_libraries (${PROJECT_NAME} "DBRx64" ${OpenCV_LIBS})
else()
target_link_libraries (${PROJECT_NAME} "DBRx86" ${OpenCV_LIBS})
endif()
endif()
else()
target_link_libraries (${PROJECT_NAME} "DynamsoftBarcodeReader" pthread ${OpenCV_LIBS})
endif()

if(WINDOWS)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/../../../platforms/win/bin/"
$<TARGET_FILE_DIR:main>)
endif()

# Set installation directory
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/dist)
if(WINDOWS)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/win/bin/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
elseif(LINUX)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/linux/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR ARM32_BUILD)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/arm32/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/aarch64/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
endif()
elseif(MACOS)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/../../../platforms/macos/" DESTINATION ${PROJECT_SOURCE_DIR}/dist)
endif()


Loading

0 comments on commit 80dbdfe

Please sign in to comment.