Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
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.

BinarizationModes

This parameter helps control the process of binarization, i.e., converting a grayscale image to a binary image. A better binary image greatly helps the process of barcode reading. During binarization, the threshold is the key criteria. If the pixel value is smaller than the threshold, it is set to 0, otherwise, it is set to a maximum value (255 in the library). By default, the library automatically calculates the adaptive size of the neighbourhood area and then binarizes the grayscale image with the adaptive threshold based on a small neighbourhood area with an adaptive size around it.

The array consists of one or more modes, each mode representing a different way to implement the binarization.

Candidate Mode List

  • BM_LOCAL_BLOCK
  • BM_THRESHOLD

BM_LOCAL_BLOCK

Binarizes the image for each pixel based on a threshold which is calculated based on a small region around it. This mode has the following arguments for further customizing.

BM_THRESHOLD

Binarizes the image for each pixel based on a unified threshold. 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. This mode has the following arguments for further customizing.

Setting Methods

As PublicRuntimeSettings Member

BinarizationModes can be set dynamically during runtime as a member of PublicRuntimeSettings struct, it is an array with 8 BinarizationMode Enumeration items.

Code Snippet in C++

//...other codes
PublicRuntimeSettings* pSettings = new PublicRuntimeSettings;
int errorCode = reader->GetRuntimeSettings(pSettings);
pSettings->binarizationModes[0] = BM_LOCAL_BLOCK;
pSettings->binarizationModes[1] = BM_THRESHOLD;
reader->UpdateRuntimeSettings(pSettings);
reader->SetModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy", "0");
reader->SetModeArgument("BinarizationModes", 1, "BinarizationThreshold", "125");
delete pSettings;
//...other codes

Remarks
GetModeArgument and SetModeArgument need to be called for getting and setting Arguments.

See Also

As JSON Parameter

BinarizationModes as a JSON parameter is a JSON Object array. Each JSON object is defined as below.

Key Name Key Value Description
Mode Any one in Candidate Mode List as string (Required) Sets a binarization mode.
BinarizationThreshold A number from value range of BinarizationThreshold (Optional) Sets the Argument BinarizationThreshold.
BlockSizeX A number from value range of BlockSizeX (Optional) Sets the Argument BlockSizeX.
BlockSizeY A number from value range of BlockSizeY (Optional) Sets the Argument BlockSizeY.
EnableFillBinaryVacancy A number from value range of EnableFillBinaryVacancy (Optional) Sets the Argument EnableFillBinaryVacancy.
ImagePreprocessingModesIndex A number from value range of ImagePreprocessingModesIndex (Optional) Sets the Argument ImagePreprocessingModesIndex.
ThresholdCompensation A number from value range of ThresholdCompensation (Optional) Sets the Argument ThresholdCompensation.
LibraryFileName A string from value range of LibraryFileName (Optional) Sets the Argument LibraryFileName.
LibraryParameters A string from value range of LibraryFileName (Optional) Sets the Argument LibraryFileName.

JSON Parameter Example

{
    "BinarizationModes": [
        {
            "Mode": "BM_LOCAL_BLOCK", 
            "BlockSizeX": 5,
            "BlockSizeY": 5
        },
        {
            "Mode": "BM_THRESHOLD", 
            "BinarizationThreshold": 125
        }
    ]
}

Candidate Argument List

BlockSizeX

Sets the horizontal block size for the binarization process.

Value Type Value Range Default Value Valid For
int [0, 1000] 0 BM_LOCAL_BLOCK

Remarks
Block size refers to the size of a pixel neighborhood used to calculate a threshold value for the pixel.

  • 0: the block size used for binarization will be set to a value which is calculated automatically.
  • N:
    • 1 <= N <= 3: the block size used for binarization will be set to 3.
    • N > 3: the block size used for binarization will be set to N.

Performance Adaptability
Setting this to an appropriate value ( 5 - 8 times module size is recommended ) may improve the Read Rate.

BlockSizeY

Sets the vertical block size for the binarization process.

Value Type Value Range Default Value Valid For
int [0, 1000] 0 BM_LOCAL_BLOCK

Remarks
Block size refers to the size of a pixel neighborhood used to calculate a threshold value for the pixel.

  • 0: the block size used for binarization will be set to a value which is calculated automatically.
  • N:
    • 1 <= N <= 3: the block size used for binarization will be set to 3.
    • N > 3: the block size used for binarization will be set to N.

Performance Adaptability
Setting this to an appropriate value ( 5 - 8 times module size is recommended ) may improve the Read Rate.

EnableFillBinaryVacancy

Sets whether to enable binary vacancy filling.

Value Type Value Range Default Value Valid For
int [0, 1] 1 BM_LOCAL_BLOCK

Remarks

  • 0: disable.
  • 1: enable.

For barcodes with a large module size, there might be a vacant area in the position detection pattern after binarization. The vacant area may result in decoding failure. Setting this to True will fill in the vacant area with black and may help improve the decoding success rate.

Performance Adaptability
Enabling this may improve the Read Rate but slowdown the Speed.

ImagePreprocessingModesIndex

The index of a specific image preprocessing mode in the ImagePreprocessingModes parameter which the current binarization mode is applied to.

Value Type Value Range Default Value Valid For
int [-1, 0x7fffffff] -1 BM_LOCAL_BLOCK
BM_THRESHOLD

Remarks
-1: The current binarization mode is applied to all modes in parameter ImagePreprocessingModes.

ThresholdCompensation

Constant subtracted from the mean or weighted mean used for calculating the threshold. Normally, it is positive but may be zero or negative as well.

Value Type Value Range Default Value Valid For
int [-255, 255] 10 BM_LOCAL_BLOCK

ThreshValueCoefficient

Deprecated. Use ThresholdCompensation instead.

BinarizationThreshold

Sets the binarization threshold.

Value Type Value Range Default Value Valid For
int [-1, 255] -1 BM_THRESHOLD

LibraryFileName

Sets the file name of the library to load dynamically.

Value Type Value Range Default Value Valid For
string A string value representing file name. ”” All modes

Remarks
The library must be in the same place with Dynamsoft Barcode Reader Library.

LibraryParameters

Sets the parameters passed to the library to load dynamically.

Value Type Value Range Default Value Valid For
string A string value representing parameters. ”” All modes

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 9.x
    • 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 +
© 2003–2022 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support