diff --git a/CMakeLists.txt b/CMakeLists.txt index b1da470..a3f8324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ option(BUILD_CPP_VIDEODECODING "Build the sample VideoDecoding under ./samples/C option(BUILD_CPP_SPEEDFIRSTSETTINGS "Build the sample SpeedFirstSettings under ./sample/C++/Performance/SpeedFirstSettings" ON) option(BUILD_CPP_ACCURACYFIRSTSETTINGS "Build the sample AccuracyFirstSettings under ./sample/C++/Performance/AccuracyFirstSettings" ON) option(BUILD_CPP_READRATEFIRSTSETTINGS "Build the sample ReadRateFirstSettings under ./sample/C++/Performance/ReadRateFirstSettings" ON) +option(BUILD_CPP_READDPMBARCODE "Build the sample ReadDPMBarcode under ./sample/C++/UseCases/ReadDPMBarcode" ON) if(BUILD_LINUX) set(DBRLIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/Linux) @@ -63,7 +64,13 @@ endif() if(BUILD_CPP_READRATEFIRSTSETTINGS) add_subdirectory(samples/C++/Performance/ReadRateFirstSettings) endif() +if(BUILD_CPP_READDPMBARCODE) + add_subdirectory(samples/C++/UseCases/ReadDPMBarcode) +endif() if(BUILD_C_HELLOWORLD OR BUILD_C_GENERALSETTINGS OR BUILD_CPP_HELLOWORLD OR BUILD_CPP_GENERALSETTINGS OR BUILD_CPP_SPEEDFIRSTSETTINGS OR BUILD_CPP_ACCURACYFIRSTSETTINGS OR BUILD_CPP_READRATEFIRSTSETTINGS) File(COPY ./images/AllSupportedBarcodeTypes.png DESTINATION images) endif() +if(BUILD_CPP_READDPMBARCODE) + File(COPY ./images/dpm.jpg DESTINATION images) +endif() diff --git a/images/dpm.jpg b/images/dpm.jpg new file mode 100644 index 0000000..3dfc0de Binary files /dev/null and b/images/dpm.jpg differ diff --git a/samples/C++/BarcodeReaderSamples.sln b/samples/C++/BarcodeReaderSamples.sln index 3e60ce7..beeb73a 100644 --- a/samples/C++/BarcodeReaderSamples.sln +++ b/samples/C++/BarcodeReaderSamples.sln @@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AccuracyFirstSettings", "Pe EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadRateFirstSettings", "Performance\ReadRateFirstSettings\ReadRateFirstSettings.vcxproj", "{AEFC9596-D16D-4790-9C56-E9F58D7B66EA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadDPMBarcode", "UseCases\ReadDPMBarcode\ReadDPMBarcode.vcxproj", "{24006433-CE29-468A-A29D-DEE568FC9B9D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -80,6 +82,14 @@ Global {AEFC9596-D16D-4790-9C56-E9F58D7B66EA}.Release|x64.Build.0 = Release|x64 {AEFC9596-D16D-4790-9C56-E9F58D7B66EA}.Release|x86.ActiveCfg = Release|Win32 {AEFC9596-D16D-4790-9C56-E9F58D7B66EA}.Release|x86.Build.0 = Release|Win32 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Debug|x64.ActiveCfg = Debug|x64 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Debug|x64.Build.0 = Debug|x64 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Debug|x86.ActiveCfg = Debug|Win32 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Debug|x86.Build.0 = Debug|Win32 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Release|x64.ActiveCfg = Release|x64 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Release|x64.Build.0 = Release|x64 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Release|x86.ActiveCfg = Release|Win32 + {24006433-CE29-468A-A29D-DEE568FC9B9D}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/samples/C++/Performance/SpeedFirstSettings/SpeedFirstSettings.cpp b/samples/C++/Performance/SpeedFirstSettings/SpeedFirstSettings.cpp index b74d6c0..c3fefe9 100644 --- a/samples/C++/Performance/SpeedFirstSettings/SpeedFirstSettings.cpp +++ b/samples/C++/Performance/SpeedFirstSettings/SpeedFirstSettings.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "../../../../include/DynamsoftBarcodeReader.h" #include "../../../../include/DynamsoftCommon.h" using namespace std; @@ -12,7 +13,6 @@ using namespace dynamsoft::dbr; #if defined(_WIN64) || defined(_WIN32) #include #include -#include #ifdef _WIN64 #pragma comment(lib, "../../../../lib/Windows/x64/DBRx64.lib") #else diff --git a/samples/C++/UseCases/ReadDPMBarcode/CMakeLists.txt b/samples/C++/UseCases/ReadDPMBarcode/CMakeLists.txt new file mode 100644 index 0000000..e847931 --- /dev/null +++ b/samples/C++/UseCases/ReadDPMBarcode/CMakeLists.txt @@ -0,0 +1,34 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR) + cmake_minimum_required(VERSION 3.6) + # set the platform + option(BUILD_LINUX "Build samples for running on Linux x86_64" ON) + option(BUILD_ARM "Build samples for running on ARM x86" OFF) + option(BUILD_ARM64 "Build samples for running on ARM x64" OFF) + + if(BUILD_LINUX) + set(DBRLIB ../../../../lib/Linux) + elseif(BUILD_ARM) + set(DBRLIB ../../../../lib/ARM32) + add_compile_options(-DDM_ARM -D__ARM_NEON__ -mfpu=neon) + elseif(BUILD_ARM64) + set(DBRLIB ../../../../lib/ARM64) + add_compile_options(-DDM_ARM -D__ARM_NEON__) + else() + message(FATAL_ERROR "Please specify a supported platform") + endif() + + set (CMAKE_CXX_STANDARD 11) + add_compile_options(-O2 -fPIC) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden -L ${DBRLIB} -Wl,-rpath,${DBRLIB} -Wl,-rpath,'$ORIGIN' -static-libgcc -static-libstdc++ -s") +endif() + +project(ReadDPMBarcode) + +file(GLOB FILE_SRCS +ReadDPMBarcode.cpp +) + +add_executable(ReadDPMBarcode ${FILE_SRCS}) +set_target_properties(ReadDPMBarcode PROPERTIES SKIP_BUILD_RPATH TRUE) +target_link_libraries(ReadDPMBarcode DynamsoftBarcodeReader) + diff --git a/samples/C++/UseCases/ReadDPMBarcode/ReadDPMBarcode.cpp b/samples/C++/UseCases/ReadDPMBarcode/ReadDPMBarcode.cpp new file mode 100644 index 0000000..f8e436b --- /dev/null +++ b/samples/C++/UseCases/ReadDPMBarcode/ReadDPMBarcode.cpp @@ -0,0 +1,124 @@ +#include +#include + +#include "../../../../include/DynamsoftBarcodeReader.h" +#include "../../../../include/DynamsoftCommon.h" + +using namespace std; +using namespace dynamsoft::dbr; + +// Link libraries of DynamsoftBarcodeReader SDK for Windows. +#if defined(_WIN64) || defined(_WIN32) +#ifdef _WIN64 +#pragma comment(lib, "../../../../lib/Windows/x64/DBRx64.lib") +#else +#pragma comment(lib, "../../../../lib/Windows/x86/DBRx86.lib") +#endif +#endif + +class ReadDPMBarcode +{ +public: + void configReadDPMBarcode(CBarcodeReader *reader) + { + // Obtain current runtime settings of instance. + PublicRuntimeSettings settings; + reader->GetRuntimeSettings(&settings); + + // Set expected barcode formats. + // Generally, the most common dpm barcode is datamatrix or qrcode + settings.barcodeFormatIds = BF_DATAMATRIX | BF_QR_CODE; + + // Set grayscale transformation modes. + // DPM barcodes may be dark and printed on the light background, or it may be light and printed on the dark background. + // By default, the library can only locate the dark barcodes that stand on a light background. "GTM_INVERTED":The image will be transformed into inverted grayscale. + settings.furtherModes.grayscaleTransformationModes[0] = GTM_ORIGINAL; + settings.furtherModes.grayscaleTransformationModes[1] = GTM_INVERTED; + + // Enable dpm modes. + // It is a parameter to control how to read direct part mark(DPM) barcodes. + settings.furtherModes.dpmCodeReadingModes[0] = DPMCRM_GENERAL; + + // Apply the new settings to the instance + reader->UpdateRuntimeSettings(&settings); + + } + + + void outputResults(TextResultArray* barcodeResults, CBarcodeReader& reader) + { + if (barcodeResults != NULL && barcodeResults->resultsCount > 0) + { + // Process each result in a loop + for (int i = 0; i < barcodeResults->resultsCount; ++i) + { + cout << "Result " << (i + 1) << ":" << endl; + + //Get format of each barcode + if (barcodeResults->results[i]->barcodeFormat != BF_NULL) + cout << " Barcode Format: " << barcodeResults->results[i]->barcodeFormatString << endl; + else + cout << " Barcode Format: " << barcodeResults->results[i]->barcodeFormatString_2 << endl; + + //Get text result of each barcode + cout << " Barcode Text: " << barcodeResults->results[i]->barcodeText << endl; + } + } + else + { + cout << "No barcode detected." << endl; + } + + //Free the memory allocated for text results + if (barcodeResults != NULL) + CBarcodeReader::FreeTextResults(&barcodeResults); + } +}; + +int main() +{ + int errorCode = 0; + char szErrorMsg[256]; + TextResultArray* barcodeResults = NULL; + + // Initialize license + /* + // By setting organization ID as "200001", a 7-day trial license will be used for license verification. + // Note that network connection is required for this license to work. + // + // When using your own license, locate the following line and specify your Organization ID. + // organizationID = "200001"; + // + // If you don't have a license yet, you can request a trial from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=c_cpp + */ + DM_DLSConnectionParameters paramters; + CBarcodeReader::InitDLSConnectionParameters(¶mters); + paramters.organizationID = const_cast("200001"); // replace it with your organization ID + errorCode = CBarcodeReader::InitLicenseFromDLS(¶mters, szErrorMsg, 256); + if (errorCode != DBR_OK) + { + cout << szErrorMsg << endl; + } + + // Create an instance of Barcode Reader + CBarcodeReader reader; + ReadDPMBarcode rb; + + string fileName = "../../../../images/dpm.jpg"; + + // config through ReadDPM + rb.configReadDPMBarcode(&reader); + + // Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings. + reader.DecodeFile(fileName.c_str(), ""); + + // Get all barcode results + reader.GetAllTextResults(&barcodeResults); + + // Output the barcode format and barcode text. + rb.outputResults(barcodeResults, reader); + + cout << "Press any key to quit..." << endl; + cin.ignore(); + return 0; +} \ No newline at end of file diff --git a/samples/C++/UseCases/ReadDPMBarcode/ReadDPMBarcode.vcxproj b/samples/C++/UseCases/ReadDPMBarcode/ReadDPMBarcode.vcxproj new file mode 100644 index 0000000..3f18489 --- /dev/null +++ b/samples/C++/UseCases/ReadDPMBarcode/ReadDPMBarcode.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {24006433-CE29-468A-A29D-DEE568FC9B9D} + ReadDPMBarcode + 10.0 + + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + + + + + \ No newline at end of file