How to Check if All the Barcodes are Found?

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
    void *hBarcode = NULL;
    int iRet = -1;
    int iIndex = 0;
    int bcodeCount = 0;
    SLocalizationResultArray *Result = NULL;
    //enter the number of existing barcodes from the files
    printf("Input the number of existing barcode in the file: \n");
    scanf_s("%d", &bcodeCount);
    hBarcode = DBR_CreateInstance(); 
    DBR_InitLicense(hBarcode, "Put your license key here"); 
    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 (bcodeCount == Result->nResultsCount)
    {
        printf("All the barcodes have been localized. \n");
    }
    //if the barcodes are not all found, runtime setting needs modification
    else if (bcodeCount >= Result->nResultsCount)
    {
        printf("Some of the barcodes have not been localized. \n");
        printf("%d codes are localized. \n", Result->nResultsCount);
    }
    DBR_FreeLocalizationResults(&Result);
    DBR_DestroyInstance(hBarcode);
    // C++
    int bcodeCount = 0;
    int iRet = 0;
    CBarcodeReader reader;
    SLocalizationResultArray *pResult;
    //enter the number of existing barcodes from the files
    printf("Input the number of existing barcodes: \n");
    scanf_s("%d", &bcodeCount);
    reader.InitLicense("Put your license key here ");
    reader.DecodeFile("Put your image or PDF file here ", "");
    iRet = reader.GetAllLocalizationResults(&pResult);
    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 == pResult->nResultsCount)
    {
        printf("All the barcodes have been found. \n");
    }
    //if the barcodes are not all found, runtime setting needs modification
    else if (bcodeCount > pResult->nResultsCount)
    {
        printf("Some of the barcodes are not been localized. \n");
    }
    CBarcodeReader::FreeLocalizationResults(&pResult);
     // 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", "");
    LocalizationResult[] localizationResult = dbr.GetAllLocalizationResults();
    //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 == localizationResult.Length)
        {
            Console.WriteLine("Barcodes have all been found");
        }
    //if the barcodes are not all found, runtime setting needs modification
    else if (i > localizationResult.Length)
        {
         Console.WriteLine("There are some barcodes not found");
        Console.WriteLine("Only {0} barcodes are found", localizationResult.Length);
        }

results matching ""

    No results matching ""