编程知识 cdmana.com

Hidden image data of dynamsoft barcode reader SDK that you don't know

Dynamsoft Barcode Reader SDK A multifunctional barcode reading control , It only needs a few lines of code to embed the barcode reading function into Web Or desktop applications . This can save months of development time and cost . It can support multiple image file formats as well as those obtained from cameras or scanners DIB Format . Use Dynamsoft Barcode Reader SDK, You can create powerful and practical barcode scanner software , To meet your business needs .

Click to download Dynamsoft Barcode Reader The latest version

Using bar codes SDK When scanning single or multiple barcodes , Most developers only care about the tradeoff between decoding speed and recognition accuracy , Because they don't have access to other data . from 8.0 version ,Dynamsoft Expose more parameters and intermediate results to developers ( for example , Grayscale image , Binary image , Bar code positioning results, etc ), To optimize and debug applications , So that Dynamsoft Barcode SDK In commercial bar codes SDK Stand out from the rest . In this paper , I will introduce some related parameters and API.

requirement

CMake
OpenCV 4.5.0 edition . about Windows, You need to OpenCV_DIR = C:\opencv\build Add environment variables to the system “ ”.

Dynamsoft Bar code reader 8.0. To unlock all features , You have to apply for a trial license .

stay CMake Links in projects OpenCV and Dynamsoft Barcode SDK

If you have successfully installed OpenCV, Then link OpenCV The library is very simple :

find_package(OpenCV REQUIRED)
if (CMAKE_HOST_WIN32)
 if (CMAKE_CL_64)
  target_link_libraries (BarcodeReaderDemo "DBRx64" ${OpenCV_LIBS})
 else ()
  target_link_libraries (BarcodeReaderDemo "DBRx86" ${OpenCV_LIBS})
 endif()
else ()
target_link_libraries (BarcodeReaderDemo "DynamsoftBarcodeReader" ${OpenCV_LIBS})
endif()

about Dynamsoft Barcode SDK, The link directory is set manually :

if (CMAKE_HOST_WIN32)
 if (CMAKE_CL_64)
  link_directories("${PROJECT_SOURCE_DIR}/lib/Windows/x64")
 else()
  link_directories("${PROJECT_SOURCE_DIR}/lib/Windows/x86")
 endif()
else if(CMAKE_HOST_UNIX)
 link_directories("${PROJECT_SOURCE_DIR}/lib/Linux")
endif()

Get the converted image and the predicted barcode bounding box

Let's see Dynamsoft How barcode readers work .

Use Dynamsoft The general method of bar code reader scanning bar code is as follows :

CBarcodeReader reader;
ret = reader.InitLicense("LICENSE-KEY");
ret = reader.DecodeFile(imageFile, templateName);
TextResultArray *finalResults = NULL;
reader.GetAllTextResults(&finalResults);
for (int index = 0; index < finalResults->resultsCount; index++)
{
  printf("Value: %s\r\n", finalResults->results[index]->barcodeText);
}

in fact , You can get more than the end result . All converted image data generated in the process of barcode decoding can be saved for future use .

DynamsoftBarcodeReader.h Some enumeration types are defined in the header file :

typedef enum IntermediateResultType
{ 
 /**No intermediate result */
 IRT_NO_RESULT = 0x00000000,

 /**Original image */
 IRT_ORIGINAL_IMAGE = 0x00000001,

 /**Colour clustered image. Not supported yet. */
 IRT_COLOUR_CLUSTERED_IMAGE = 0x00000002,

 /**Colour image converted to grayscale  */
 IRT_COLOUR_CONVERTED_GRAYSCALE_IMAGE = 0x00000004,

 /**Transformed grayscale image */
 IRT_TRANSFORMED_GRAYSCALE_IMAGE = 0x00000008,

 /**Predetected region */
 IRT_PREDETECTED_REGION = 0x00000010,

 /**Preprocessed image */
 IRT_PREPROCESSED_IMAGE = 0x00000020,

 /**Binarized image */
 IRT_BINARIZED_IMAGE = 0x00000040,

 /**Text zone */
 IRT_TEXT_ZONE = 0x00000080,

 /**Contour */
 IRT_CONTOUR = 0x00000100,

 /**Line segment */
 IRT_LINE_SEGMENT = 0x00000200,

 /**Form. Not supported yet. */
 IRT_FORM = 0x00000400,

 /**Segmentation block. Not supported yet. */
 IRT_SEGMENTATION_BLOCK = 0x00000800,

 /**Typed barcode zone */
 IRT_TYPED_BARCODE_ZONE = 0x00001000,

 /**Predetected quadrilateral*/
 IRT_PREDETECTED_QUADRILATERAL = 0x00002000

}IntermediateResultType;

According to the definition , It's easy to infer Dynamsoft What image processing algorithms are used . Now? , I'll write some code snippets to show you how to get grayscale images , Binary images and bar code bounding boxes .
Before decoding the barcode image , Please configure the intermediate data to be obtained :

reader.GetRuntimeSettings(&runtimeSettings);
runtimeSettings.barcodeFormatIds = barcodeFormat.barcodeFormatIds;
runtimeSettings.barcodeFormatIds_2 = barcodeFormat.barcodeFormatIds_2;
runtimeSettings.intermediateResultSavingMode = IRSM_MEMORY;
runtimeSettings.intermediateResultTypes = IRT_BINARIZED_IMAGE | IRT_TRANSFORMED_GRAYSCALE_IMAGE | IRT_TYPED_BARCODE_ZONE;
runtimeSettings.scaleDownThreshold = 10000;
ret = reader.UpdateRuntimeSettings(&runtimeSettings, errorMSG, 256);

By default , The save mode is IRSM_MEMORY. If you want to save data to the file system , It can be changed to IRSM_FILESYSTEM. Described scaleDownThreshold Used to control the input image size . If the width of the input image is greater than the threshold , The image will be scaled down .

After calling the decoding method , We can call GetIntermediateResults() To get a list of mixed data :

IntermediateResultArray* intermediateResults = NULL;
reader.GetIntermediateResults(&intermediateResults);
for (int i = 0; i < intermediateResults->resultsCount; i++)
{
}

If the data type is IMRDT_IMAGE, You can get the image buffer :

if(intermediateResults->results[i]->dataType == IMRDT_IMAGE)
{
 int type = 0;
 ImageData* imageData = (ImageData*)intermediateResults->results[i]->results[0];
 switch(imageData->format)
 {
 case IPF_BINARY:
 case IPF_GRAYSCALED:
 case IPF_BINARYINVERTED:
  type = CV_8UC1;
  break;
 case IPF_RGB_888:
  type = CV_8UC3;
  break;
 default:
  break;
 }
}

If the data type is IMRDT_LOCALIZATIONRESULT, Then you can get the barcode bounding box :

if (intermediateResults->results[i]->dataType == IMRDT_LOCALIZATIONRESULT
{
 LocalizationResult *pLocalizationResult = (LocalizationResult *)intermediateResults->results[i]->results[0];
 int x1 = pLocalizationResult->x1;
 int y1 = pLocalizationResult->y1;
 int x2 = pLocalizationResult->x2;
 int y2 = pLocalizationResult->y2;
 int x3 = pLocalizationResult->x3;
 int y3 = pLocalizationResult->y3;
 int x4 = pLocalizationResult->x4;
 int y4 = pLocalizationResult->y4;
}

We use OpenCV imshow() Function displays the converted image and barcode bounding box .

Grayscale image

多条形码灰度图像

Binary image

二进制图像

Bar code bounding box

条码边框

You can write code to explore Dynamsoft Barcode SDK More intermediate data generated .


Want to buy Dynamsoft Barcode Reader The original authorization , Or for more product information, please click 【 Consult online customer service 】

版权声明
本文为[roffey]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224172417485b.html

Scroll to Top