Code Monkey home page Code Monkey logo

barcode-reader-python-samples's Introduction

Dynamsoft Barcode Reader samples for Python edition

Current version number Supported Python versions PyPI downloads

Dynamsoft

Overview

This repository contains multiple samples that demonstrate how to use the Dynamsoft Barcode Reader Python Edition.

Requirements

Supported Platforms

  • Windows x64
  • Linux (x64, ARM32, ARM64)
  • macOS (10.15+)

Supported Python Versions

  • Python 3.6
  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10
  • Python 3.11
  • Python 3.12

Installation

pip install dbr

or

pip3 install dbr

Samples

Sample Name Description
hello-world Shows the simplest way to recognize barcodes from images in Python using Dynamsoft Barcode Reader SDK.
general-settings Shows how to adjust general scan settings, e.g., barcode format, barcode count, scan region.
image-decoding Shows how to decode images in various formats, e.g., file bytes, opencv image, raw image buffer.
video-decoding Shows how to decode barcodes from a video from a file or camera.
video-decoding-for-picamera Shows how to scan barcodes from videos from a Raspberry Pi camera (PiCamera).
batch-decode Shows how to batch decode image files from a specified folder.
speed-first-settings Shows how to configure the scan settings for best barcode reading speed.
read-rate-first-settings Shows how to configure the scan settings to read as many barcodes as possible at one time. Recommended when decoding multiple barcodes from a single image.
accuracy-first-settings Shows how to configure the scan settings for best barcode reading accuracy.
read-dpm-barcode Shows how to read DPM (Direct Part Mark) barcodes.

Documentation

https://www.dynamsoft.com/barcode-reader/docs/server/programming/python/?ver=latest&utm_source=samples

License

The barcode reader library requires a license to work. You can use the API init_license to initialize the license key and activate the SDK.

These samples use a free public trial license which requires a network connection to function. You can request a 30-day free trial license key from Customer Portal which works offline.

Contact Us

https://www.dynamsoft.com/company/contact/

barcode-reader-python-samples's People

Contributors

claire-chan avatar dmgithubpublisher avatar dynamsoft-jerson avatar francisjc avatar owenlyn0123 avatar rachel-dynamsoft avatar sprice89 avatar yushulx avatar zorowang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

barcode-reader-python-samples's Issues

python pip version not found

Hi
when i do

pip3 install dbr

get error

Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement dbr (from versions: none)
ERROR: No matching distribution found for dbr

my python version is : Python 3.10.1

using dbr for detecting QR code coordinates

i want to ask if i install the dbr code "pip install dbr", to only use for detecting qr code and get the coordinates of it is this free ?
i am not sure because i am not using any "license_key" for detecting qr code and it coordinate. could you please explain what is on the pay price of dbr qr code.

result points returned not showing the localized bar code properly with opencv

I am trying to visualize the results of the scanned bar/QR Codes with opencv. But the localization_result.localization_points returned is not giving the correct position of the Codes in the image. Below is the output that i am getting.
Screenshot from 2020-11-18 19-02-18
The result is always found on the top right corner of the image. Can anyone please explain how the result points data can be configured properly?

Below is my python visualization code

import os
import sys
import cv2
import json
from typing import List
from dbr import *
import glob
import random
import pandas as pd

def showResult(image,result):

    cv2.namedWindow("DynamoSoft Result", cv2.WINDOW_NORMAL)

    points = result["points"]
    cv2.line(image, points[0], points[1], color, thickness)
    cv2.line(image, points[1], points[2], color, thickness)
    cv2.line(image, points[2], points[3], color, thickness)
    cv2.line(image, points[3], points[0], color, thickness)
    cv2.putText(image, result['parsed'], points[0], cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255)) 
    
    # image = cv2.resize(image, (1560, 940))
    cv2.imshow("DynamoSoft Result",image)
    #add wait key. window waits till user press any key
    cv2.waitKey(0)
    #and finally destroy/Closing all open windows
    cv2.destroyWindow("DynamoSoft Result") 


# you can replace the following variables' value with yours.
license_key = "my_key"
#license_server = "Input the name/IP of the license server"
json_file = r"./settings.json"
image = r"./../test_images/IMG_0273.JPG"
# image_folder = r"./../test_images/画像元データ/*/"
image_folder = r"./../test_images/画像元データ/12.部品単体_TMコントロールECU_ラベル2/"

# To show results on image
thickness = 2
color = (0,255,0)

reader = BarcodeReader()

reader.init_license(license_key)
error = reader.init_runtime_settings_with_file(json_file)

if error[0] != EnumErrorCode.DBR_OK:
    print(error[1])


full_results = []
for idx, img in enumerate(glob.glob(os.path.join(image_folder, "*.*"))):
    result_dict = []
    print(f"Reading {img}")
    # print('Test', idx+1)
    print(40*'#')
    
    try:
        image = cv2.imread(img)
        text_results:List[TextResult] = reader.decode_buffer(image)

        if text_results != None:
            
            for text_result in text_results:
                result_list = {}
                result_list["filename"]= img
                result_list["format"] = text_result.barcode_format_string 
                result_list["parsed"] = text_result.barcode_text
                result_list["points"] = text_result.localization_result.localization_points


                print("Barcode Format :")
                print(text_result.barcode_format_string)
                print("Barcode Text :")
                print(text_result.barcode_text)
                print("Localization Points : ")
                print(text_result.localization_result.localization_points)
                print(text_result.localization_result.result_coordinate_type)
                print("-------------")
                showResult(image,result_list)
                result_dict.append(result_list)
    except BarcodeReaderError as bre:
        print(bre)
        
    
    full_results.append(result_dict)
    # print(full_results)
    print(40*'#')
# print(full_results)

And this is the settings.json file that i am using

// https://demo.dynamsoft.com/DBR/BarcodeReaderDemo.aspx
{
    "ImageParameter": {
      "AccompanyingTextRecognitionModes": [
        {
          "Mode": "ATRM_SKIP"
        }
      ],
      "BarcodeColourModes": [
        {
          "LightReflection": 1,
          "Mode": "BICM_DARK_ON_LIGHT"
        }
      ],
      "BarcodeComplementModes": [
        {
          "Mode": "BCM_SKIP"
        }
      ],
      "BarcodeFormatIds": [
        "BF_ALL"
      ],
      "BarcodeFormatIds_2": [
        "BF2_POSTALCODE",
        "BF2_DOTCODE"
      ],
      "BinarizationModes": [
        {
          "BlockSizeX": 0,
          "BlockSizeY": 0,
          "EnableFillBinaryVacancy": 1,
          "ImagePreprocessingModesIndex": -1,
          "Mode": "BM_LOCAL_BLOCK",
          "ThreshValueCoefficient": 10
        },
        {
          "BlockSizeX": 0,
          "BlockSizeY": 0,
          "EnableFillBinaryVacancy": 0,
          "ImagePreprocessingModesIndex": -1,
          "Mode": "BM_LOCAL_BLOCK",
          "ThreshValueCoefficient": 15
        }
      ],
      "ColourClusteringModes": [
        {
          "Mode": "CCM_SKIP"
        }
      ],
      "ColourConversionModes": [
        {
          "BlueChannelWeight": -1,
          "GreenChannelWeight": -1,
          "Mode": "CICM_GENERAL",
          "RedChannelWeight": -1
        }
      ],
      "DPMCodeReadingModes": [
        {
          "Mode": "DPMCRM_GENERAL"
        }
      ],
      "DeblurLevel": 9,
      "DeformationResistingModes": [
        {
          "Level": 5,
          "Mode": "DRM_GENERAL"
        }
      ],
      "Description": "",
      "ExpectedBarcodesCount": 999,
      "FormatSpecificationNameArray": null,
      "GrayscaleTransformationModes": [
        {
          "Mode": "GTM_ORIGINAL"
        },
        {
          "Mode": "GTM_INVERTED"
        }
      ],
      "ImagePreprocessingModes": [
        {
          "Mode": "IPM_GENERAL"
        }
      ],
      "IntermediateResultSavingMode": {
        "Mode": "IRSM_MEMORY"
      },
      "IntermediateResultTypes": [
        "IRT_NO_RESULT"
      ],
      "LocalizationModes": [
        {
          "Mode": "LM_CONNECTED_BLOCKS"
        },
        {
          "Mode": "LM_SCAN_DIRECTLY",
          "ScanDirection": 0,
          "ScanStride": 0
        },
        {
          "Mode": "LM_STATISTICS"
        },
        {
          "Mode": "LM_LINES"
        },
        {
          "Mode": "LM_STATISTICS_MARKS"
        },
        {
          "Mode": "LM_STATISTICS_POSTAL_CODE"
        }
      ],
      "MaxAlgorithmThreadCount": 4,
      "Name": "default",
      "PDFRasterDPI": 300,
      "PDFReadingMode": {
        "Mode": "PDFRM_AUTO"
      },
      "Pages": "",
      "RegionDefinitionNameArray": [
        "default"
      ],
      "RegionPredetectionModes": [
        {
          "Mode": "RPM_GENERAL"
        }
      ],
      "ResultCoordinateType": "RCT_PERCENTAGE",
      "ReturnBarcodeZoneClarity": 0,
      "ScaleDownThreshold": 99999,
      "ScaleUpModes": [
        {
          "Mode": "SUM_AUTO"
        }
      ],
      "TerminatePhase": "TP_BARCODE_RECOGNIZED",
      "TextAssistedCorrectionMode": {
        "BottomTextPercentageSize": 0,
        "LeftTextPercentageSize": 0,
        "Mode": "TACM_VERIFYING",
        "RightTextPercentageSize": 0,
        "TopTextPercentageSize": 0
      },
      "TextFilterModes": [
        {
          "MinImageDimension": 65536,
          "Mode": "TFM_GENERAL_CONTOUR",
          "Sensitivity": 0
        }
      ],
      "TextResultOrderModes": [
        {
          "Mode": "TROM_CONFIDENCE"
        },
        {
          "Mode": "TROM_POSITION"
        },
        {
          "Mode": "TROM_FORMAT"
        }
      ],
      "TextureDetectionModes": [
        {
          "Mode": "TDM_GENERAL_WIDTH_CONCENTRATION",
          "Sensitivity": 5
        }
      ],
      "Timeout": 99999
    },
    "RegionDefinition": {
      "BarcodeFormatIds": [
        "BF_ALL"
      ],
      "BarcodeFormatIds_2": [
        "BF2_POSTALCODE",
        "BF2_DOTCODE"
      ],
      "Bottom": 100,
      "ExpectedBarcodesCount": 0,
      "FormatSpecificationNameArray": null,
      "Left": 0,
      "MeasuredByPercentage": 1,
      "Name": "default",
      "Right": 100,
      "Top": 0
    },
    "Version": "3.0"
  }

Does not install on raspberry pi

I am running on a raspberry pip model 3b+, python version 3.5.3, pip 20.2.2. I am using Raspian stretch. I get the following error:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement dbr (from versions: none)
ERROR: No matching distribution found for dbr

Fatal Python error: deallocating None

We are facing a problem ( Looks like a memory leak ) that when we use it to read lots of images ( We use it in real time ) it causes a crash.

We get this error :
Fatal Python error: deallocating None
Python runtime state: initialized

Current thread 0x00007f110c588740 (most recent call first):
File "debug.py", line 14 in
Aborted (core dumped)

This can happen after 700 uses but cal also take up to 8000 uses before it happens. It appears random.

We have tested this on 3 different PC's with the following test code and we always get the crash.

`import cv2
from dbr import *

json_file = r"Please input your own template path"
license_key = "t0070fQAAAGaeApMwKH9QQqOMMKYqbpPriea3LzpS5GgmGMt9Cf2DUrmrSErh6JDgXPrYyKjIwirB+VFpBavnrn8qJDf6qaYbhw=="
reader = BarcodeReader()
reader.init_license(license_key)

image = cv2.imread("1.jpg")

i=0
while 0 == 0:
text_results = reader.decode_buffer(image)
DataMatrixResult = len(text_results)
print("loop_number = ",i)
i=i+1`

Fatal Python error: deallocating None / Process finished with exit code 137

Hi Dynamsoft team. I work for Zenus that provides analytics solutions for events, which includes QR code scanning. We have obtained a number of Dynamsoft QR code scanning licenses for our devices in order to provide this service, and are now facing an issue.
We use the video mode of the library ( dbr.start_video_mode(**params) ), in order to have both a live feed and asynchronous QR code decoding. What happens is that after some time, probably due to a memory leak we get the error of the title [Fatal Python error: deallocating None].
When running your python example, we get a similar error after some time that indicates issues with accessing memory [Process finished with exit code 137].

This doesn't have to do with QR code version, as it happens without presenting any QR codes during runtime after some time.

I have seen that there was an update regarding this, but it seems that it wasn't completely solved. Bellow you can find information about our setup.

  • Platform: Jetson Xavier NX
  • OS: balenalib/jetson-xavier-nx-devkit-emmc-ubuntu (bionic)
  • Python version: 3.6.9
  • DBR library version: (latest) 9.6.20

Any help resolving this, or any updates on a fix would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.