Read Inverted Barcodes
Typically, barcodes are dark on a light background. But in some cases, the barcodes are “inverted” – light barcodes on a dark background, as shown in the image below.
Inverted Barcodes
The feature to decode such inverted barcodes is not enabled by default. To control this feature, we must use the GrayscaleTransformationModes
. Now for a quick breakdown of each of the modes:
- With only
GTM_ORIGINAL
enabled inGrayscaleTransformationModes
, DBR scans only general black-on-white barcodes. - With only
GTM_INVERTED
enabled inGrayscaleTransformationModes
, DBR scans only inverted barcodes. - When
GTM_ORIGINAL
is enabled as the first mode andGTM_INVERTED
is enabled as the second mode inGrayscaleTransformationModes
, DBR will try to decode general barcodes first. If the count of decoded barcodes does not reach the expected number, DBR will then try decoding the inverted barcodes.
To allow for inverted barcodes, add the value GTM_INVERTED
to GrayscaleTransformationModes
as shown in the code snippet below:
- JavaScript
- Android
- Objective-C
- Swift
- C
- C++
- C#
- Java
- Python
// Obtains the current runtime settings of DBR. let settings = await scanner.getRuntimeSettings(); // Adds GTM_INVERTED to grayscaleTransformationModes. settings.furtherModes.grayscaleTransformationModes = [Dynamsoft.DBR.EnumGrayscaleTransformationMode.GTM_ORIGINAL, Dynamsoft.DBR.EnumGrayscaleTransformationMode.GTM_INVERTED]; // Updates the settings. await scanner.updateRuntimeSettings(settings);
// Obtain current runtime settings of `reader` instance. PublicRuntimeSettings settings = reader.getRuntimeSettings(); // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.furtherModes.grayscaleTransformationModes = new int[]{EnumGrayscaleTransformationMode.GTM_ORIGINAL, EnumGrayscaleTransformationMode.GTM_INVERTED}; // Update the settings. reader.updateRuntimeSettings(settings);
NSError* err = nil; // Obtain current runtime settings of `reader` instance. iPublicRuntimeSettings* settings = [reader getRuntimeSettings:&err]; // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.furtherModes.grayscaleTransformationModes = @[@(EnumGrayscaleTransformationModeOriginal),@(EnumGrayscaleTransformationModeInverted)]; // Update the settings. [reader updateRuntimeSettings:settings error:&err];
// Obtain current runtime settings of `barcodeReader` instance. let settings = try? barcodeReader.getRuntimeSettings() // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings?.furtherModes.grayscaleTransformationModes = [EnumGrayscaleTransformationMode.original, EnumGrayscaleTransformationMode.inverted] // Update the settings. try? barcodeReader.updateRuntimeSettings(settings!)
PublicRuntimeSettings settings; char szErrorMsg[256] = {0}; // Obtain current runtime settings of `reader` instance. DBR_GetRuntimeSettings(reader, &settings); // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.furtherModes.grayscaleTransformationModes[0] = GTM_ORIGINAL; settings.furtherModes.grayscaleTransformationModes[1] = GTM_INVERTED; // Update the settings. DBR_UpdateRuntimeSettings(reader, &settings, szErrorMsg, 256);
PublicRuntimeSettings settings; char szErrorMsg[256] = {0}; // Obtain current runtime settings of `reader` instance. reader.GetRuntimeSettings(&settings); // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.furtherModes.grayscaleTransformationModes[0] = GTM_ORIGINAL; settings.furtherModes.grayscaleTransformationModes[1] = GTM_INVERTED; // Update the settings. reader.UpdateRuntimeSettings(&settings, szErrorMsg, 256);
// Obtain current runtime settings of `reader` instance. PublicRuntimeSettings settings = reader.GetRuntimeSettings(); // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.FurtherModes.GrayscaleTransformationModes[0] = GTM_ORIGINAL; settings.FurtherModes.GrayscaleTransformationModes[1] = GTM_INVERTED; // Update the settings. reader.UpdateRuntimeSettings(settings);
// Obtain current runtime settings of `reader` instance. PublicRuntimeSettings settings = reader.getRuntimeSettings(); // Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.furtherModes.grayscaleTransformationModes = new int[]{EnumGrayscaleTransformationMode.GTM_ORIGINAL, EnumGrayscaleTransformationMode.GTM_INVERTED}; // Update the settings. reader.updateRuntimeSettings(settings);
# Obtain current runtime settings of `reader` instance. settings = reader.get_runtime_settings() # Add GTM_INVERTED to GrayscaleTransformationModes to decode inverted barcodes. settings.grayscale_transformation_modes[0] = EnumGrayscaleTransformationMode.GTM_ORIGINAL settings.grayscale_transformation_modes[1] = EnumGrayscaleTransformationMode.GTM_INVERTED # Update the settings. reader.update_runtime_settings(settings)