Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

How to Recognize Accompanying Text

In some scenarios, especially for 1D barcodes, a barcode can be accompanied by human readable text. This accompanying text might be useful for barcode value verification, or for further use in your application. Currently, DBR only supports the recognition of the accompanying text with 1D barcodes.

DBR provides the AccompanyingTextRecognitionModes parameter which allows you to recognize the accompanying text near the barcode. The parameter AccompanyingTextRecognitionModes is an array of AccompanyingTextRecognitionMode values.

AccompanyingTextRecognitionMode has the following enumeration values:

Enumeration Member Enumeration Value Description
ATRM_SKIP 0x00 Turn off accompanying text recognition
ATRM_GENERAL 0x01 Turn on accompanying text recognition

The default searching area for accompanying text

When AccompanyingTextRecognitionMode is set to ATRM_GENERAL, the accompanying text recognition feature is enabled. By default, DBR uses the successfully decoded barcode as a reference, and tries to recognize possible accompanying text in close proximity around the barcode.

The following is a sample image:

standard-acompanying-text

DBR is able to recognize the accompanying text marked by the red when accompanying text recognition is enabled.

JSON template example:

{
    "ImageParameter": {
        "Name": "ImageParameter1", 
        "Description": "This is acompanying text demonstrate", 
        "AccompanyingTextRecognitionModes":["ATRM_GENERAL"]
    }, 
    "Version": "3.0"
}  

Set a custom area for accompanying text

In some scenarios, the accompanying text you need is not in the immediate vicinity of the barcode. You can set a custom area to search by using the successfully decoded barcode as a reference via top, bottom, left and right values. The unit is in percentage.

Let’s take the following image as an example. In this sample image, the information we would like to recognize is within the green box, but it is a relatively far from the barcode. We can specify a custom searching area (marked by the red box) by setting the following arguments:

RegionBottom = -150, RegionLeft = -12, RegionRight = 85, RegionTop = -250

a card image demo that has a customed acompanying text recognition range

Example JSON template:

{
    "ImageParameter": {
        "Name": "ImageParameter1", 
        "Description": "This is a acompanying text demonstrate", 
        "AccompanyingTextRecognitionModes":[
            {
                "Mode" : "ATRM_GENERAL",
                "RegionBottom" : -150,
                "RegionLeft" : -12,
                "RegionRight" : 85,
                "RegionTop" : -250
            }
        ]
    }, 
    "Version": "3.0"
}  

How to get the result of recognized accompanying text

The result of the accompanying text is stored in the decoding result: ExtendedResult -> type RT_STANDARD_TEXT. The following code snippet shows how to get the result of recognized accompanying text.

CBarcodeReader * reader = new CBarcodeReader;
reader->InitLicense("Insert your license here");
char error[512];
int ret = reader->InitRuntimeSettingsWithFile("JsonTemplate.txt",CM_OVERWRITE,error,512);
ret = reader->DecodeFile("Insert image file path here");
TextResultArray* pResults = NULL;
reader->GetAllTextResults(&pResults);
for(int resultId = 0; resultId < pResults->resultsCount; ++resultId)
{
    TextResult* pBarcode = pResults->results[resultId];
    string accompany;
    // Loop through all ExtendedResult
    for(int extendId = 0; extendId < pBarcode->resultsCount; ++extendId)
    {
        PExtendedResult pExtend = pBarcode->results[extendId];
        if(pExtend->resultType == RT_STANDARD_TEXT)
        {
            unsigned char * accompanyStr = pExtend->accompanyingTextBytes;
            int strLen = pExtend->accompanyingTextBytesLength;
            accompany = string(accompanyStr,accompanyStr + strLen);
            break;
        }    
    }
    if(!accompany.empty())
    {
        cout << "accompanyText: " << accompany << endl;
    }
}
CBarcodeReader::FreeTextResults(&pResults);
delete reader;

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

latest version

    • Latest version
    • Version 10.x
      • Version 10.2.0
      • Version 10.0.21
      • Version 10.0.20
      • Version 10.0.10
      • Version 10.0.0
    • Version 9.x
      • Version 9.6.40
      • Version 9.6.33
      • Version 9.6.32
      • Version 9.6.31
      • Version 9.6.30
      • Version 9.6.20
      • Version 9.6.10
      • Version 9.6.0
      • Version 9.4.0
      • Version 9.2.0
      • Version 9.0.0
    • Version 8.x
      • Version 8.8.0
      • Version 8.6.0
      • Version 8.4.0
      • Version 8.2.0
      • Version 8.1.2
      • Version 8.1.0
      • Version 8.0.0
    • Version 7.x
      • Version 7.6.0
      • Version 7.5.0
    Change +