ImagePreprocessingModes
This parameter provides some image processing methods to enhance the quality of the grayscale image before reading barcodes. By default, the library does no preprocessing method. Assume your image has distorted features that can be solved by common image processing methods, this parameter may help set the processing mode(s) for getting a higher quality grayscale image.
It consists of one or more modes, each mode is a way to implement the preprocessing algorithm.
Candidate Mode List
- IPM_GENERAL
- IPM_GRAY_EQUALIZE
- IPM_GRAY_SMOOTH
- IPM_SHARPEN_SMOOTH
- IPM_MORPHOLOGY
IPM_GENERAL
Keeps the original grayscale. This mode has the following arguments for further customizing.
IPM_GRAY_EQUALIZE
Preprocesses the image using the gray equalization algorithm. This mode can be used for images with low contrast on barcode and background colour. This mode has the following arguments for further customizing.
IPM_GRAY_SMOOTH
Preprocesses the image using the gray smoothing algorithm. This mode can be used for images with noise or texture. This mode has the following arguments for further customizing.
IPM_SHARPEN_SMOOTH
Preprocesses the image using the sharpening and smoothing algorithm. This mode can be used for blur images. This mode has the following arguments for further customizing.
- SmoothBlockSizeX
- SmoothBlockSizeY
- SharpenBlockSizeX
- SharpenBlockSizeY
- LibraryFileName
- LibraryParameters
IPM_MORPHOLOGY
Preprocesses the image using the morphology algorithm. It can be used for images where the barcode area is polluted or destroyed. This mode has the following arguments for further customizing.
- MorphOperation
- MorphShape
- MorphOperationKernelSizeX
- MorphOperationKernelSizeY
- LibraryFileName
- LibraryParameters
Setting Methods
As PublicRuntimeSettings
Member
ImagePreprocessingModes
can be set dynamically during runtime as a member of FurtherModes
, which is a member of PublicRuntimeSettings
struct, it is an array with 8 ImagePreprocessingMode
Enumeration items.
Code Snippet in C++
//...other codes
PublicRuntimeSettings* pSettings = new PublicRuntimeSettings;
int errorCode = reader->GetRuntimeSettings(pSettings);
pSettings->imagePreprocessingModes[0] = IPM_GRAY_SMOOTH;
pSettings->imagePreprocessingModes[1] = IPM_GRAY_EQUALIZE;
reader->UpdateRuntimeSettings(pSettings);
reader->SetModeArgument("ImagePreprocessingModes", 1, "Sensitivity", "1");
delete pSettings;
//...other codes
Remarks
GetModeArgument
and SetModeArgument
need to be called for getting and setting Arguments
.
See Also
PublicRuntimeSettings:
JavaScript | C | C++ | .NET | Python | Java | Java-Android | Objective-C & SwiftImagePreprocessingMode:
JavaScript | C | C++ | .NET | Python | Java | Java-Android | Objective-C & SwiftGetModeArgument:
JavaScript | C | C++ | .NET | Python | Java | Java-Android | Objective-C & SwiftSetModeArgument:
JavaScript | C | C++ | .NET | Python | Java | Java-Android | Objective-C & Swift
As JSON Parameter
ImagePreprocessingModes
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 preprocessing mode. |
Sensitivity | A number from value range of Sensitivity | (Optional) Sets the Argument Sensitivity. |
SmoothBlockSizeX | A number from value range of SmoothBlockSizeX | (Optional) Sets the Argument SmoothBlockSizeX. |
SmoothBlockSizeY | A number from value range of SmoothBlockSizeY | (Optional) Sets the Argument SmoothBlockSizeY. |
SharpenBlockSizeX | A number from value range of SharpenBlockSizeX | (Optional) Sets the Argument SmoothBlockSizeX. |
SharpenBlockSizeY | A number from value range of SharpenBlockSizeY | (Optional) Sets the Argument SmoothBlockSizeY. |
MorphOperation | A string from value range of MorphOperation | (Optional) Sets the Argument MorphOperation. |
MorphOperation | A string from value range of MorphOperation | (Optional) Sets the Argument MorphOperation. |
MorphOperationKernelSizeX | A number from value range of MorphOperationKernelSizeX | (Optional) Sets the Argument MorphOperationKernelSizeX. |
MorphOperationKernelSizeY | A number from value range of MorphOperationKernelSizeY | (Optional) Sets the Argument MorphOperationKernelSizeY. |
LibraryFileName | A string from value range of LibraryFileName | (Optional) Sets the Argument LibraryFileName. |
LibraryParameters | A string from value range of LibraryParameters | (Optional) Sets the Argument LibraryParameters. |
JSON Parameter Example
{
"ImagePreprocessingModes": [
{
"Mode": "IPM_GRAY_SMOOTH",
"SmoothBlockSizeX": 5,
"SmoothBlockSizeY": 5
},
{
"Mode": "IPM_GRAY_EQUALIZE",
"Sensitivity": 1
}
]
}
Candidate Argument List
- Sensitivity
- SmoothBlockSizeX
- SmoothBlockSizeY
- SharpenBlockSizeX
- SharpenBlockSizeY
- MorphOperation
- MorphShape
- MorphOperationKernelSizeX
- MorphOperationKernelSizeY
- LibraryFileName
- LibraryParameters
Sensitivity
Sets the sensitivity to perform the equalization process. A larger value means a higher possibility that gray equalization will be activated.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
int | [1, 9] | 5 | IPM_GRAY_EQUALIZE |
Performance Adaptability
A larger value may cause adverse effect on Speed and Read Rate on images with a high level of contrast.
SmoothBlockSizeX
Sets the horizontal block size for the smoothing process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
int | [3, 1000] | 3 | IPM_GRAY_SMOOTH IPM_SHARPEN_SMOOTH |
Remarks
Block size refers to the size of a pixel neighborhood used to calculate a threshold value for the pixel.
Performance Adaptability
Setting this to an appropriate value ( 5 - 8 times module size is recommended ) may improve the Read Rate.
SmoothBlockSizeY
Sets the vertical block size for the smoothing process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
int | [3, 1000] | 3 | IPM_GRAY_SMOOTH IPM_SHARPEN_SMOOT |
Remarks
Block size refers to the size of a pixel neighborhood used to calculate a threshold value for the pixel.
Performance Adaptability
Setting this to an appropriate value ( 5 - 8 times module size is recommended ) may improve the Read Rate.
SharpenBlockSizeX
Sets the horizontal block size for the sharpening process.
Value Type | Value Range | Default Value | |
---|---|---|---|
int | [3, 1000] | 3 | IPM_SHARPEN_SMOOTH |
Remarks
Block size refers to the size of a pixel neighborhood used to calculate the threshold for the pixel. An appropriate value can help increase the accuracy of barcode localization.
SharpenBlockSizeY
Sets the vertical block size for the sharpening process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
int | [3, 1000] | 3 | IPM_SHARPEN_SMOOTH |
Remarks
Block size refers to the size of a pixel neighborhood used to calculate the threshold for the pixel. An appropriate value can help increase the accuracy of barcode localization.
MorphOperation
Sets the morph operation for the morphology process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
string | Erode Dilate Open Close |
Close |
IPM_MORPHOLOGY |
Remarks
Erode
: Perform erosion process.Dilate
: Perform dilation process.Open
: Perform erosion first, then perform dilation.Close
: Perform dilation first, then perform erosion.
For more information, please check out Image Processing in OpenCV - Morphological Transformations for reference.
MorphShape
Sets the morph shape for the morphology process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
string | Rectangle Cross Ellipse |
Rectangle |
IPM_MORPHOLOGY |
MorphOperationKernelSizeX
Sets the horizontal kernel size for the morphology process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
int | [0, 1000] | 0 | IPM_MORPHOLOGY |
MorphOperationKernelSizeY
Sets the vertical kernel size for the morphology process.
Value Type | Value Range | Default Value | Valid For |
---|---|---|---|
int | [0, 1000] | 0 | IPM_MORPHOLOGY |
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 |