General Example

Import needed Modules#

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

            

Creating Barkoder Configuration#

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

Enabling Symbologies#

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

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

Setting Barkoder Settings#

                	#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#

                	#---------------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#

                    #---------------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--------------
            

Page Contents

History:

close