On this page

Stuck? Open a support ticket and the barKoder team will help. Open a ticket

Python General example

Import needed Modules #

Python
from Barkoder import BarkoderSDK
import json
import numpy as np
import cv2 as cv

Creating Barkoder Configuration #

Python
status = BarkoderSDK.initialize("LICENSE_KEY");
print("SDK status: ", status)

Enabling Symbologies #

Python
QR = BarkoderSDK.constants["Decoders"]["QR"];
PDF417 = BarkoderSDK.constants["Decoders"]["PDF417"];

#set desired decoders
decoders = [QR, PDF417];
BarkoderSDK.setEnabledDecoders(decoders);

Setting Barkoder Settings #

Python
#set desired decodingSpeed
decodingSpeed = BarkoderSDK.constants["DecodingSpeed"]["Normal"];
BarkoderSDK.setDecodingSpeed(decodingSpeed);

#set desired ROI
BarkoderSDK.setRegionOfInterest(0, 0, 100, 100);

#set desired DPM mode
BarkoderSDK.setDatamatrixDpmModeEnabled(False);

Performing a Decode / Scan #

Python
#---------------read and scan an image---------
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)

Handling and Showing Results #

Python
#---------------handle the result--------------
result = json.loads(result_json)

print("resultsCount: ", result["resultsCount"])

# the result is a Python dictionary:
if result["resultsCount"] == 1:
    print(result["barcodeTypeName"])
    print(result["textualData"])

elif result["resultsCount"] > 1:
    for res in result["results"]:
        print(res["barcodeTypeName"])
        print(res["textualData"])
        print("---------------------------")

else:
    print("No barcode found.")
#---------------handle the result--------------