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 Read Barcodes with Uneven Lighting

In some scenarios, the captured barcode image may have inconsistent lighting across the barcode. For example, the following image shows a barcode image with uneven lighting.

Sample barcode image with uneven lighting

Figure 1 – Sample barcode image with uneven lighting

Converting the original barcode image to a binarized image is a very important step. Dynamsoft Barcode Reader (DBR) provides two binarization modes:

  • BM_THRESHOLD: uses a global threshold to binarize the image. If the gray value of the pixel is less than the threshold, it will be black in the binary image, otherwise it will be white.
  • BM_LOCAL_BLOCK: use a threshold for a pixel based on a small region around it.

The following two images show the effects of BM_THRESHOLD (global thresholding) and BM_LOCAL_BLOCK (local thresholding).

Binarized image by global thresholding

Figure 2 – Binarized image by global thresholding

Binarized image by local thresholding

Figure 3 – Binarized image by local thresholding

Obviously, the local thresholding result is much better. Now we will demonstrate how to configure the parameter BinarizationModes to achieve the effect mentioned above.

Particular Parameter Required

DBR provides a parameter BinarizationModes that allows you to control the conversion of a grayscale image to a binary image.

Sample Code

Below is an example illustrating how to configure the parameter BinarizationModes.

  • update parameter BinarizationModes in your JSON template

      {
          "CaptureVisionTemplates": [
              {
                  "Name": "CV_0",
                  "ImageROIProcessingNameArray": ["TA_0" ]
              }       
          ],
          "TargetROIDefOptions" : [
              {
                  "Name": "TA_0",
                  "TaskSettingNameArray": [ "BR_0" ]
              }
          ],
          "BarcodeReaderTaskSettingOptions": [
              {
                  "Name" : "BR_0",
                  "SectionImageParameterArray": [
                      {
                          "Section": "ST_REGION_PREDETECTION",
                          "ImageParameterName": "IP_0"
                      },
                      {
                          "Section": "ST_BARCODE_LOCALIZATION",
                          "ImageParameterName": "IP_0"
                      },
                      {
                          "Section": "ST_BARCODE_DECODING",
                          "ImageParameterName": "IP_0"
                      }
                  ]
              }
          ],
          "ImageParameterOptions": [
              {
                  "Name": "IP_0",
                  "BinarizationModes": [
                      {
                          "Mode": "BM_LOCAL_BLOCK",
                          "BlockSizeX": 0,
                          "BlockSizeY": 0,
                          "EnableFillBinaryVacancy": 1,
                          "ThresholdCompensation": 10
                      }
                  ]
              }
          ]
      }
    
  • apply settings by calling method InitSettingsFromFile

  • C++
  • Android
  • Objective-C
  • Swift
char szErrorMsg[256] = {0};
CCaptureVisionRouter* cvr = new CCaptureVisionRouter;
cvr->InitSettingsFromFile("PATH-TO-YOUR-SETTING-FILE", szErrorMsg, 256);
// more process here
try {
   // `cvr` is an instance of `CaptureVisionRouter`.
   cvr.initSettingsFromFile("PATH-TO-YOUR-SETTING-FILE");
} catch (CaptureVisionRouterException e) {
   e.printStackTrace();
}
NSError *error;
// `cvr` is an instance of `DSCaptureVisionRouter`.
[self.cvr initSettingsFromFile:@"PATH-TO-YOUR-SETTING-FILE" error:&error];
do{
   //`cvr` is an instance of `CaptureVisionRouter`.
   try cvr.initSettingsFromFile("PATH-TO-YOUR-SETTING-FILE")
}catch{
   // Add code to do when error occurs.
}

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

latest version

  • Latest version
  • Version 10.x
    • Version 10.0.21
    • Version 10.0.20
    • Version 10.0.10
    • Version 10.0.0
  • Version 9.x
    • 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 +