Python API Reference
This page will explain all available methods and configuration settings of the barKoder Barcode Scanner SDK for Python.
Import the barKoder Barcode Scanner SDK for Python with
from Barkoder import BarkoderSDK
Methods#
The API methods are available under the BarkoderSDK module (i.e. BarkoderSDK.methodName
).
getLibVersion()#
Gets the SDK version.
Returns SDK version as str
(Text Type).
Syntax:
getLibVersion(): str
Usage example:
version = BarkoderSDK.getLibVersion();
print("SDK version: ", version)
initialize(licenseKey)#
Initializes the SDK with a license key.
Parameters:
licenseKey: str
Returns licensing status as str
(Text Type).
Syntax:
initialize(licenseKey: str): str
Usage example:
status = BarkoderSDK.initialize("LICENSE_KEY"); print("SDK status: ", status)
decodeImage(image, width, height)#
Scans grayscale array of image memory.
Parameters:
image: numpy.ndarray
width: int
height: int
Returns JSON result as str
(Text Type) with the following fields:
resultsCount: int
barcodeTypeName: str
textualData: str
binaryData: list where each element is an int
location: dict, containing
p1: dict, containing
x: float
y: float
p2: dict, containing
x: float
y: float
p3: dict, containing
x: float
y: float
p4: dict, containing
x: float
y: float
gs1: int
The resultsCount field determines the result structure.
resultsCount 0 means no results were found, and remaining fields will not be present.
resultsCount 1 means exactly one barcode result was found and above fields will be present.
resultsCount 2 or higher means multiple barcode results were found, and result fields are as follows:
resultsCount: int
results: list, where each element is a dict with the following fields:
barcodeTypeName: str
textualData: str
binaryData: list where each element is an int
location: dict, containing
p1: dict, containing
x: float
y: float
p2: dict, containing
x: float
y: float
p3: dict, containing
x: float
y: float
p4: dict, containing
x: float
y: float
gs1: int
Syntax:
decodeImage(image: numpy.ndarray, width: int, height: int): str
Usage example:
import json
import numpy as np
import cv2 as cv
img = cv.imread('qr.bmp', cv.IMREAD_GRAYSCALE)
assert img is not None, "file could not be read, check with os.path.exists()"
height, width = img.shape[:2]
result_json = BarkoderSDK.decodeImage(img, width, height)
result = json.loads(result_json)
setRegionOfInterest(left, top, width, height)#
Sets the ROI.
Parameters:
left: float
top: float
width: float
height: float
Returns NoneType
(None Type).
Syntax:
setRegionOfInterest(left: float, top: float, width: float, height: float): NoneType
Usage example:
BarkoderSDK.setRegionOfInterest(0, 0, 100, 100);
getRegionOfInterest()#
Gets the ROI.
Returns str
(Text Type).
Syntax:
getRegionOfInterest(): str
Usage example:
roi_json = BarkoderSDK.getRegionOfInterest();
roi = json.loads(roi_json)
setDecodingSpeed(decodingSpeed) #
Sets the decoding speed.
Parameters:
decodingSpeed: int
The values for this setting are available under BarkoderSDK.constants["DecodingSpeed"]
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setDecodingSpeed(decodingSpeed: int): int
Usage example:
decodingSpeed = BarkoderSDK.constants["DecodingSpeed"]["Slow"];
BarkoderSDK.setDecodingSpeed(decodingSpeed);
setEnabledDecoders(decoders, numberOfDecoders) #
Sets the decoders to enable.
Parameters:
decoders
: list
, where each element has a value from BarkoderSDK.constants["Decoders"]
numberOfDecoders
: int
, the len of the above list
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setEnabledDecoders(decoders: int, numberOfDecoders: int): int
Usage example:
decoders = BarkoderSDK.constants["Decoders"];
QR = decoders["QR"];
PDF417 = decoders["PDF417"];
Code128 = decoders["Code128"];
Datamatrix = decoders["Datamatrix"];
Code93 = decoders["Code93"];
Code39 = decoders["Code39"];
#set desired decoders
decoders = [QR, PDF417, Code128, Datamatrix, Code93, Code39];
total_decoders = len(decoders);
BarkoderSDK.setEnabledDecoders(decoders, total_decoders);
setUpcEanDeblur(upcEanDeblur) #
Sets the deblur for UPC and EAN codes.
Parameters:
upcEanDeblur: int
The values for this setting are available under BarkoderSDK.constants["UpcEanDeblur"]
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setUpcEanDeblur(upcEanDeblur: int): int
Usage example:
upcEanDeblur = BarkoderSDK.constants["UpcEanDeblur"]["Enable"];
BarkoderSDK.setUpcEanDeblur(upcEanDeblur);
setLengthRange(decoder, minimumLength, maximumLength) #
Sets the length range for 1D codes.
Parameters:
decoder: int, a value from BarkoderSDK.constants["Decoders"]
minimumLength: int
maximumLength: int
Returns int
(Numeric Type).
Syntax:
setLengthRange(decoder: int, minimumLength: int, maximumLength: int): int
Usage example:
decoder = BarkoderSDK.constants["Decoders"]["Code39"];
BarkoderSDK.setLengthRange(decoder, 5, 50);
setFormatting(formatting) #
Sets the formatting of the result.
Parameters:
formatting: int
The values for this setting are available under BarkoderSDK.constants["Formatting"]
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setFormatting(formatting: int): int
Usage example:
formatting = BarkoderSDK.constants["Formatting"]["AAMVA"];
BarkoderSDK.setFormatting(formatting);
setDuplicatesDelayMs(duplicatesDelayMs) #
Sets the the delay between duplicate codes in ms.
Parameters:
duplicatesDelayMs: int
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax::
setDuplicatesDelayMs(duplicatesDelayMs: int): int
Usage example:
BarkoderSDK.setDuplicatesDelayMs(1000);
setMaximumResultsCount(maximumResultsCount) #
Sets the maximum results returned.
Parameters:
maximumResultsCount: int
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setMaximumResultsCount(maximumResultsCount: int): int
Usage example:
BarkoderSDK.setMaximumResultsCount(10);
setMulticodeCachingEnabled(multicodeCachingEnabled) #
Sets multicode caching.
Parameters:
multicodeCachingEnabled: int, accepts 0 (disable) and 1 (enable)
Returns int (Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setMulticodeCachingEnabled(multicodeCachingEnabled: int): int
Usage example:
BarkoderSDK.setMulticodeCachingEnabled(1);
setMulticodeCachingDuration(multicodeCachingDuration) #
Sets multicode caching duration. Note: this setting typically is beneficial if scanning from a live camera stream.
Parameters:
multicodeCachingDuration: int
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setMulticodeCachingDuration(multicodeCachingDuration: int): int
Usage example:
BarkoderSDK.setMulticodeCachingDuration(3000);
setEnableMisshaped1D(enableMisshaped1D) #
Sets detection of misshaped 1D codes.
Parameters:
enableMisshaped1D: int
The values for this setting are available under BarkoderSDK.constants["EnableMisshaped1D"]
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setEnableMisshaped1D(enableMisshaped1D: int): int
Usage example:
enableMisshaped1D = BarkoderSDK.constants["EnableMisshaped1D"]["Enable"];
BarkoderSDK.setEnableMisshaped1D(enableMisshaped1D);
setEnableVINRestrictions(enableVINRestrictions) #
Sets VIN Restrictions.
Parameters:
enableVINRestrictions: int
The values for this setting are available under BarkoderSDK.constants["EnableVINRestrictions"]
Returns int
(Numeric Type).
A value of 0 if OK, a value of -1 otherwise (argument was not good and nothing was done).
Syntax:
setEnableVINRestrictions(enableVINRestrictions: int): int
Usage example:
enableVINRestrictions = BarkoderSDK.constants["EnableVINRestrictions"]["Enable"];
BarkoderSDK.setEnableVINRestrictions(enableVINRestrictions);
setSpecificConfig(decoder, value) #
Sets a specific decoder config.
Parameters:
decoder: int,
a value from BarkoderSDK.constants["Decoders"]
value: int,
a flag value specific for the decoder
Returns int
(Numeric Type).
Syntax:
setSpecificConfig(decoder: int, value: int): int
Usage example:
decoder = BarkoderSDK.constants["Decoders"]["Msi"];
msiChecksumType = BarkoderSDK.constants["MsiChecksumType"]["mod1010"];
BarkoderSDK.setSpecificConfig(decoder, msiChecksumType);
Note: there are shorthand methods for setting specific configs for certain decoders (will be listed below). The above example for setting MSI checksum type can alternatively be done with:
msiChecksumType = BarkoderSDK.constants["MsiChecksumType"]["mod1010"];
BarkoderSDK.setMsiChecksumType(msiChecksumType);
setCode11ChecksumType(code11ChecksumType) #
Sets Code11 checksum type.
Parameters:
code11ChecksumType: int,
a value from BarkoderSDK.constants["Code11ChecksumType"]
Returns NoneType
(None Type).
Syntax:
setCode11ChecksumType(code11ChecksumType: int): NoneType
Usage example:
code11ChecksumType = BarkoderSDK.constants["Code11ChecksumType"]["single"];
BarkoderSDK.setCode11ChecksumType(code11ChecksumType);
setCode39ChecksumType(code39ChecksumType) #
Sets Code39 checksum type.
Parameters:
code39ChecksumType: int
, a value from BarkoderSDK.constants["Code39ChecksumType"]
Returns NoneType
(None Type).
Syntax:
setCode39ChecksumType(code39ChecksumType: int): NoneType
Usage example:
code39ChecksumType = BarkoderSDK.constants["Code39ChecksumType"]["enabled"];
BarkoderSDK.setCode39ChecksumType(code39ChecksumType);
setMsiChecksumType(msiChecksumType) #
Sets MSI checksum type.
Parameters:
msiChecksumType: int
, a value from BarkoderSDK.constants["MsiChecksumType"]
Returns NoneType
(None Type).
Syntax:
setMsiChecksumType(msiChecksumType: int): NoneType
Usage example:
msiChecksumType = BarkoderSDK.constants["MsiChecksumType"]["mod1010"];
BarkoderSDK.setMsiChecksumType(msiChecksumType);
setDatamatrixDpmModeEnabled(dpmModeEnabled) #
Sets DPM mode.
Parameters:
dpmModeEnabled: bool
Returns NoneType
(None Type).
Syntax:
setDatamatrixDpmModeEnabled(dpmModeEnabled: bool): NoneType
Usage example:
BarkoderSDK.setDatamatrixDpmModeEnabled(true);
getDecodingSpeed() #
Gets the decoding speed.
Returns decoding speed as int
(Numeric Type).
Syntax:
getDecodingSpeed(): int
Usage example:
decodingSpeed = BarkoderSDK.getDecodingSpeed();
print("decodingSpeed: ", decodingSpeed)
Note: numerical value for decodingSpeed can be matched with corresponding key from BarkoderSDK.constants["DecodingSpeed"]
for textual representation.
getUpcEanDeblur() #
Gets the deblur for UPC and EAN codes.
Returns deblur as int
(Numeric Type).
Syntax:
getUpcEanDeblur(): int
Usage example:
upcEanDeblur = BarkoderSDK.getUpcEanDeblur();
print("upcEanDeblur: ", upcEanDeblur)
Note: numerical value for upcEanDeblur
can be matched with corresponding key from BarkoderSDK.constants["UpcEanDeblur"]
for textual representation.
getFormatting() #
Gets the formatting.
Returns formatting as int (Numeric Type).
Syntax:
getFormatting(): int
Usage example:
formatting = BarkoderSDK.getFormatting();
print("formatting: ", formatting)
Note: numerical value for formatting can be matched with corresponding key from BarkoderSDK.constants["Formatting"]
for textual representation.
getDuplicatesDelayMs() #
Gets the duplicates delay in ms.
Returns delay as int (Numeric Type).
Syntax:
getDuplicatesDelayMs(): int
Usage example:
duplicatesDelayMs = BarkoderSDK.getDuplicatesDelayMs();
print("duplicatesDelayMs: ", duplicatesDelayMs)
getMaximumResultsCount() #
Gets the maximum results count.
Returns maximum results count as int
(Numeric Type).
Syntax:
getMaximumResultsCount(): int
Usage example:
maximumResultsCount = BarkoderSDK.getMaximumResultsCount();
print("maximumResultsCount: ", maximumResultsCount)
getEnableMisshaped1D() #
Gets the misshaped 1D enabled state.
Returns enableMisshaped1D setting as int (Numeric Type).
Syntax:
getEnableMisshaped1D(): int
Usage example:
enableMisshaped1D = BarkoderSDK.getEnableMisshaped1D();
print("enableMisshaped1D: ", enableMisshaped1D)
Note: numerical value for enableMisshaped1D can be matched with corresponding key from BarkoderSDK.constants["EnableMisshaped1D"]
for textual representation.
getEnableVINRestrictions() #
Gets the VIN restrictions enabled state.
Returns enableVINRestrictions
setting as int
(Numeric Type).
Syntax:
getEnableVINRestrictions(): int
Usage example:
enableVINRestrictions = BarkoderSDK.getEnableVINRestrictions();
print("enableVINRestrictions: ", enableVINRestrictions)
Note: numerical value for enableVINRestrictions can be matched with corresponding key from BarkoderSDK.constants["EnableVINRestrictions"]
for textual representation.
Constants #
The SDK constants are available under the BarkoderSDK module (i.e. BarkoderSDK.constants).
DecodingSpeed #
-
"Fast":
int(0)
-
"Normal":
int(1)
-
"Slow":
int(2)
-
"Rigorous":
int(3)
Note: "Rigorous" / int(3) is quite demanding on the device hardware - it may find more results, but will also take longer to do so. It is only recommended when scanning from an image.
Usage example:
decodingSpeed = BarkoderSDK.constants["DecodingSpeed"]["Slow"];
BarkoderSDK.setDecodingSpeed(decodingSpeed);
Decoders #
-
"Aztec":
int(0)
-
"AztecCompact":
int(1)
-
"QR":
int(2)
-
"QRMicro":
int(3)
-
"Code128":
int(4)
-
"Code93":
int(5)
-
"Code39":
int(6)
-
"Codabar":
int(7)
-
"Code11":
int(8)
-
"Msi":
int(9)
-
"UpcA":
int(10)
-
"UpcE":
int(11)
-
"UpcE1":
int(12)
-
"Ean13":
int(13)
-
"Ean8": i
nt(14)
-
"PDF417":
int(15)
-
"PDF417Micro":
int(16)
-
"Datamatrix":
int(17)
-
"Code25":
int(18)
-
"Interleaved25":
int(19)
-
"ITF14":
int(20)
-
"IATA25":
int(21)
-
"Matrix25":
int(22)
-
"Datalogic25":
int(23)
-
"COOP25":
int(24)
-
"Code32":
int(25)
-
"Telepen":
int(26)
-
"Dotcode":
int(27)
Usage example:
decoders = BarkoderSDK.constants["Decoders"];
QR = decoders["QR"];
PDF417 = decoders["PDF417"];
Code128 = decoders["Code128"];
Datamatrix = decoders["Datamatrix"];
Code93 = decoders["Code93"];
Code39 = decoders["Code39"];
#set desired decoders
decoders = [QR, PDF417, Code128, Datamatrix, Code93, Code39];
total_decoders = len(decoders);
BarkoderSDK.setEnabledDecoders(decoders, total_decoders);
Code11ChecksumType #
- "disabled": int(0)
- "single": int(1)
- "double": int(2)
Usage example:
code11ChecksumType = BarkoderSDK.constants["Code11ChecksumType"]["single"]; BarkoderSDK.setCode11ChecksumType(code11ChecksumType);
Code39ChecksumType #
- "disabled": int(0)
- "enabled": int(1)
Usage example:
code39ChecksumType = BarkoderSDK.constants["Code39ChecksumType"]["enabled"];
BarkoderSDK.setCode39ChecksumType(code11ChecksumType);
MsiChecksumType #
- "disabled": int(0)
- "mod10": int(1)
- "mod11": int(2)
- "mod1010": int(3)
- "mod1110": int(4)
- "mod11IBM": int(5)
- "mod1110IBM": int(6)
Usage example:
msiChecksumType = BarkoderSDK.constants["MsiChecksumType"]["mod1010"];
BarkoderSDK.setMsiChecksumType(msiChecksumType);
UpcEanDeblur #
- "Disable": int(0)
- "Enable": int(1)
Usage example:
upcEanDeblur = BarkoderSDK.constants["UpcEanDeblur"]["Enable"];
BarkoderSDK.setUpcEanDeblur(upcEanDeblur);
MulticodeCachingEnabled #
- "Disable": int(0)
- "Enable": int(1)
Usage example:
multicodeCachingEnabled = BarkoderSDK.constants["MulticodeCachingEnabled"]["Enable"];
BarkoderSDK.setMulticodeCachingEnabled(multicodeCachingEnabled);
EnableMisshaped1D #
- "Disable": int(0)
- "Enable": int(1)
Usage example:
enableMisshaped1D = BarkoderSDK.constants["EnableMisshaped1D"]["Enable"]; BarkoderSDK.setEnableMisshaped1D(enableMisshaped1D);
EnableVINRestrictions #
- "Disable": int(0)
- "Enable": int(1)
Usage example:
enableVINRestrictions = BarkoderSDK.constants["EnableVINRestrictions"]["Enable"];
BarkoderSDK.setEnableVINRestrictions(enableVINRestrictions);
Formatting
- "Disabled": int(0)
- "Automatic": int(1)
- "GS1": int(2)
- "AAMVA": int(3)
Usage example:
formatting = BarkoderSDK.constants["Formatting"]["AAMVA"];
BarkoderSDK.setFormatting(formatting);