How to Check if All the Barcodes are Decoded?

The circumstance that the program is not able to all the barcodes in the provided file may occur from time to time. Poor quality of the file and inappropriate runtime settings may both lead to the failure of decoding all the barcodes.

This article provides a simple method to check if all the barcodes within the file provided are localized. To obtain such goal, a function called GetAllLocalizationResults is required. This article provides demo in C/C++ and C#.

    // C
    int main(){
    void *hBarcode = NULL;
    int iRet = -1;
    int iIndex = 0;
    int iLicMsg = -1;
    int barcodeCount = 0; //number of barcodes 
    TextResultArray* pResult = NULL;
    PublicRuntimeSettings runtimesettings;
    hBarcode = DBR_CreateInstance();
    //enter the number of existing barcodes from the files
    printf("Input the number of existing barcode in the file: \n");
    scanf_s("%d", &barcodeCount);

    iLiceMsg = DBR_InitLicense(hBarcode, "Put your license key here"); 
    //If error occurs to the license
    if (iLicMsg != DBR_OK) {
        printf("Failed to initialize the license successfully: %d\r\n%s\r\n", iLicMsg, DBR_GetErrorString(iLicMsg));
        return iLicMsg;
    }
    DBR_DecodeFile(hBarcode, "Put your image or PDF file here", "");
    iRet = DBR_GetAllLocalizationResults(hBarcode, &Result);
    if (iRet != DBR_OK)
    {
        printf("Failed to read barcode: %d\r\n%s\r\n", iRet, DBR_GetErrorString(iRet));
        return iRet;
    }

    //check if the barcodes are all decoded successfully
    //The value of nResultCount shows the number of barcodes the SDK successfully localizes. 
    //But having localized barcodes does not necessarily mean that the barcodes are all decoded successfully.
    //The SDK may be able to localize the barcode but not able to decode them due to poor quality or other reasons. 

    if (barcodeCount == pResult->resultsCount)
    {
        printf("All the barcodes have been localized. \n");
    }
    //if the barcodes are not all found, runtime setting needs modification
    else if (barcodeCount >= pResult->resultsCount)
    {
        printf("Some of the barcodes have not been localized. \n");
        printf("%d codes are localized. \n", pResult->resultsCount);
    }
    DBR_FreeTextResults(&pResult);
    DBR_DestroyInstance(hBarcode);
    return 0;
    }
    // C++
    int main()
    {
    int iRet = -1;
    int iLicMsg = -1;
    TextResultArray* paryResult = NULL;
    PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
    CBarcodeReader* reader = new CBarcodeReader();

    //enter the number of existing barcodes from the files
    printf("Input the number of existing barcodes: \n");
    scanf_s("%d", &barcodeCount);
    iLicMsg = reader->InitLicense("Put your license key here ");
    if (iLicMsg != DBR_OK) 
    {
        printf("Failed to initialize the license successfully: %d\r\n%s\r\n", iLicMsg, DBR_GetErrorString(iLicMsg));
        return iLicMsg;
    }
    reader->DecodeFile("Put your image or PDF file here ", "");
    iRet = reader->GetAllLocalizationResults(&paryResult);
    if (iRet != DBR_OK)
    {
        printf("Error occurred. \n");
        return iRet;
    }
    //check if the barcodes are all decoded successfully
    //The value of nResultCount shows the number of barcodes the SDK successfully localizes. 
    //But having localized barcodes does not necessarily mean that the barcodes are all decoded successfully.
    //The SDK may be able to localize the barcode but not able to decode them due to poor quality or other reasons. 
    if (bcodeCount == paryResult->resultsCount)
    {
        printf("All the barcodes have been found. \n");
    }
    //if the barcodes are not all found, runtime setting needs modification
    else if (bcodeCount > paryResult->resultsCount)
    {
        printf("Some of the barcodes are not been localized. \n");
    }
    CBarcodeReader::FreeTextResults(&paryResult);
    delete runtimeSettings;
    delete reader;
    return 0;
    }
     // C#
    int i = 0;
    Console.WriteLine("Enter the number of existing barcodes: ");
    i = Convert.ToInt32(Console.ReadLine());
    BarcodeReader dbr = new BarcodeReader("Put your license key here");
    TextResult[] aryResult = dbr.DecodeFile("Put your image or pdf file here", "");
    //check if the barcodes are all decoded successfully

    //The value of Length shows the number of barcodes the SDK successfully localizes. 
    //But having localized barcodes does not necessarily mean that the barcodes are all decoded successfully.
    //The SDK may be able to localize the barcode but not able to decode them due to poor quality or other reasons. 
    if (i == aryResult.Length)
        {
            Console.WriteLine("Barcodes have all been found");
        }
    //if the barcodes are not all found, runtime setting needs modification
    else if (i > aryResult.Length)
        {
         Console.WriteLine("There are some barcodes not found");
        Console.WriteLine("Only {0} barcodes are found", aryResult.Length);
        }

results matching ""

    No results matching ""