diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 889e105..2dc33df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest] + os: [windows-latest, ubuntu-latest, macos-latest] python-version: ['3.11', '3.12'] steps: @@ -17,19 +17,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} - - - name: Set up QEMU - if: runner.os == 'Linux' - uses: docker/setup-qemu-action@v2 - with: - platforms: all - - - name: Build wheels - uses: pypa/cibuildwheel@v2.6.1 - env: - CIBW_BUILD: "cp39-*" - CIBW_ARCHS_LINUX: auto, aarch64 + python-version: ${{ matrix.python-version }} - name: Run test.py in develop mode run: | @@ -38,10 +26,6 @@ jobs: python --version python test.py - - uses: actions/upload-artifact@v2 - with: - path: ./wheelhouse/*.whl - build_sdist: name: Build source distribution runs-on: ubuntu-latest @@ -63,6 +47,23 @@ jobs: # alternatively, to publish when a GitHub Release is created, use the following rule: # if: github.event_name == 'release' && github.event.action == 'published' steps: + - name: Set up QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v2 + with: + platforms: all + + - name: Build wheels + uses: pypa/cibuildwheel@v2.6.1 + env: + CIBW_BUILD: "cp39-*" + CIBW_ARCHS_LINUX: auto, aarch64 + + + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl + - uses: actions/download-artifact@v2 with: name: artifact diff --git a/examples/official/9.x/arm32_arm64/DockerfileArm32 b/examples/official/9.x/arm32_arm64/DockerfileArm32 new file mode 100644 index 0000000..20306bd --- /dev/null +++ b/examples/official/9.x/arm32_arm64/DockerfileArm32 @@ -0,0 +1,5 @@ +FROM arm32v7/python + +RUN apt-get update && apt-get install -y cmake libgl1-mesa-glx +RUN pip install dbr opencv-python pillow + diff --git a/examples/official/9.x/arm32_arm64/DockerfileArm64 b/examples/official/9.x/arm32_arm64/DockerfileArm64 new file mode 100644 index 0000000..31bd700 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/DockerfileArm64 @@ -0,0 +1,5 @@ +FROM arm64v8/python + +RUN apt-get update && apt-get install -y cmake libgl1-mesa-glx +RUN pip install dbr opencv-python pillow + diff --git a/examples/official/9.x/arm32_arm64/README.md b/examples/official/9.x/arm32_arm64/README.md new file mode 100644 index 0000000..7711dc9 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/README.md @@ -0,0 +1,38 @@ +# Docker Images for Python Barcode Detection on ARM64 and ARM32 +This repository provides a guide on how to use the Dynamsoft Barcode Reader Python SDK within Docker containers designed for ARM64 and ARM32 architectures. + +## Building Docker Images for ARM64 and ARM32 + +To build Docker images for ARM64 and ARM32, execute the following commands: + +```bash +docker run --rm --privileged multiarch/qemu-user-static:register --reset +docker build --platform linux/arm64 -f DockerfileArm64 -t . +docker build --platform linux/arm/v7 -f DockerfileArm32 -t . +``` + +## Running Python Barcode Detection in Docker Containers + +To run barcode detection using the Python script inside a Docker container, use these commands: + +```bash +docker run --platform linux/arm64 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp python pillow_test.py +docker run --platform linux/arm/v7 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp python pillow_test.py +``` + +**Try the Pre-built Images** + +You can also try the pre-built images directly: + +```bash +docker run --platform linux/arm64 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp yushulx/dbr-arm64:1.0 python pillow_test.py +docker run --platform linux/arm/v7 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp yushulx/dbr-arm32:1.0 python pillow_test.py +``` + +## Emulating Raspberry Pi +Use [dockerpi](https://github.com/lukechilds/dockerpi) to test the performance of the Python Barcode SDK on Raspberry Pi emulators: + +```bash +docker run -it lukechilds/dockerpi pi2 +docker run -it lukechilds/dockerpi pi3 +``` \ No newline at end of file diff --git a/examples/official/9.x/arm32_arm64/capture.py b/examples/official/9.x/arm32_arm64/capture.py new file mode 100644 index 0000000..bddbbf6 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/capture.py @@ -0,0 +1,29 @@ +import cv2 as cv +from dbr import * + +capture = cv.VideoCapture(0) + +if not capture.isOpened(): + print("Cannot open camera") + exit() + +BarcodeReader.init_license( + "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") +reader = BarcodeReader() + +index = 0 + +while True: + frame = capture.read()[1] + cv.imshow("frame", frame) + + if cv.waitKey(1) == ord('q'): + break + + results = reader.decode_buffer(frame) + if results != None and len(results) > 0: + cv.imwrite('images/' + str(index) + '.png', frame) + index += 1 + + if index == 10: + break diff --git a/examples/official/9.x/arm32_arm64/cv_test.py b/examples/official/9.x/arm32_arm64/cv_test.py new file mode 100644 index 0000000..62b99ed --- /dev/null +++ b/examples/official/9.x/arm32_arm64/cv_test.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +import os +import cv2 as cv +from dbr import * +import dbr +import time + + +def main(): + print('version: ' + dbr.__version__) + BarcodeReader.init_license( + "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") + + reader = BarcodeReader() + reader.init_runtime_settings_with_file( + 'faster.json', conflict_mode=EnumConflictMode.CM_OVERWRITE) + + # read file list + folder = '../../../../images' + target_dir = os.path.join(os.getcwd(), folder) + + if os.path.exists(target_dir): + filelist = os.listdir(target_dir) + + index = 0 + while index < 5: + file = filelist[index] + filapath = os.path.join(target_dir, file) + + if os.path.isfile(filapath): + image = cv.imread(filapath) + + start_time = time.time() + results = reader.decode_buffer(image) + elapsed_time = time.time() - start_time + + print(filelist[0] + ", elapsed time: " + + str(round(elapsed_time * 1000)) + "ms, ") + if results != None: + for result in results: + print(result.barcode_format_string + + ': ' + result.barcode_text) + else: + print(' results: 0') + + index += 1 + + +if __name__ == '__main__': + main() diff --git a/examples/official/9.x/arm32_arm64/faster.json b/examples/official/9.x/arm32_arm64/faster.json new file mode 100644 index 0000000..fb22e57 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/faster.json @@ -0,0 +1,233 @@ +{ + "FormatSpecification": { + "AllModuleDeviation": 0, + "AustralianPostEncodingTable": "C", + "BarcodeAngleRangeArray": null, + "BarcodeBytesLengthRangeArray": [ + { + "MaxValue": 2147483647, + "MinValue": 0 + } + ], + "BarcodeBytesRegExPattern": "", + "BarcodeComplementModes": null, + "BarcodeFormatIds": [ + "BF_ALL" + ], + "BarcodeFormatIds_2": [ + "BF2_ALL" + ], + "BarcodeHeightRangeArray": null, + "BarcodeTextLengthRangeArray": [ + { + "MaxValue": 2147483647, + "MinValue": 0 + } + ], + "BarcodeTextRegExPattern": "", + "BarcodeWidthRangeArray": null, + "BarcodeZoneBarCountRangeArray": null, + "BarcodeZoneMinDistanceToImageBorders": 0, + "Code128Subset": "", + "DeblurLevel": 9, + "DeformationResistingModes": null, + "EnableDataMatrixECC000-140": 0, + "EnableQRCodeModel1": 0, + "FindUnevenModuleBarcode": 1, + "HeadModuleRatio": "", + "MSICodeCheckDigitCalculation": "MSICCDC_MOD_10", + "MinQuietZoneWidth": 4, + "MinRatioOfBarcodeZoneWidthToHeight": 0, + "MinResultConfidence": 30, + "MirrorMode": "MM_NORMAL", + "ModuleSizeRangeArray": null, + "Name": "defaultFormatParameterForAllBarcodeFormat", + "PartitionModes": [ + "PM_WHOLE_BARCODE", + "PM_ALIGNMENT_PARTITION" + ], + "PatchCodeSearchingMargins": { + "Bottom": 20, + "Left": 20, + "MeasuredByPercentage": 1, + "Right": 20, + "Top": 20 + }, + "RequireStartStopChars": 1, + "ReturnPartialBarcodeValue": 1, + "StandardFormat": "", + "TailModuleRatio": "", + "VerifyCheckDigit": 0 + }, + "ImageParameter": { + "BarcodeColourModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "LightReflection": 1, + "Mode": "BICM_DARK_ON_LIGHT" + } + ], + "BarcodeComplementModes": [ + { + "Mode": "BCM_SKIP" + } + ], + "BarcodeFormatIds": [ + "BF_ALL" + ], + "BarcodeFormatIds_2": [ + "BF2_NULL" + ], + "BinarizationModes": [ + { + "BlockSizeX": 0, + "BlockSizeY": 0, + "EnableFillBinaryVacancy": 1, + "ImagePreprocessingModesIndex": -1, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "BM_LOCAL_BLOCK", + "ThresholdCompensation": 10 + } + ], + "ColourClusteringModes": [ + { + "Mode": "CCM_SKIP" + } + ], + "ColourConversionModes": [ + { + "BlueChannelWeight": -1, + "GreenChannelWeight": -1, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "CICM_GENERAL", + "RedChannelWeight": -1 + } + ], + "DPMCodeReadingModes": [ + { + "Mode": "DPMCRM_SKIP" + } + ], + "DeblurLevel": 9, + "DeblurModes": null, + "DeformationResistingModes": [ + { + "Level": 5, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "DRM_GENERAL" + } + ], + "Description": "", + "ExpectedBarcodesCount": 0, + "FormatSpecificationNameArray": [ + "defaultFormatParameterForAllBarcodeFormat" + ], + "GrayscaleTransformationModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "GTM_ORIGINAL" + } + ], + "ImagePreprocessingModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "IPM_GENERAL" + } + ], + "IntermediateResultSavingMode": { + "Mode": "IRSM_MEMORY" + }, + "IntermediateResultTypes": [ + "IRT_NO_RESULT" + ], + "LocalizationModes": [ + { + "IsOneDStacked": 0, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "LM_SCAN_DIRECTLY", + "ScanDirection": 0, + "ScanStride": 0 + }, + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "LM_CONNECTED_BLOCKS" + }, + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "LM_STATISTICS" + } + ], + "MaxAlgorithmThreadCount": 1, + "Name": "default", + "PDFRasterDPI": 300, + "PDFReadingMode": { + "Mode": "PDFRM_AUTO" + }, + "Pages": "", + "RegionDefinitionNameArray": null, + "RegionPredetectionModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "RPM_GENERAL" + } + ], + "ResultCoordinateType": "RCT_PERCENTAGE", + "ReturnBarcodeZoneClarity": 0, + "ScaleDownThreshold": 2300, + "ScaleUpModes": [ + { + "Mode": "SUM_AUTO" + } + ], + "TerminatePhase": "TP_BARCODE_RECOGNIZED", + "TextAssistedCorrectionMode": { + "BottomTextPercentageSize": 0, + "LeftTextPercentageSize": 0, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "TACM_VERIFYING", + "RightTextPercentageSize": 0, + "TopTextPercentageSize": 0 + }, + "TextFilterModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "MinImageDimension": 65536, + "Mode": "TFM_GENERAL_CONTOUR", + "Sensitivity": 0 + } + ], + "TextResultOrderModes": [ + { + "Mode": "TROM_CONFIDENCE" + }, + { + "Mode": "TROM_POSITION" + }, + { + "Mode": "TROM_FORMAT" + } + ], + "TextureDetectionModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "TDM_GENERAL_WIDTH_CONCENTRATION", + "Sensitivity": 5 + } + ], + "Timeout": 10000 + }, + "Version": "3.0" +} \ No newline at end of file diff --git a/examples/official/9.x/arm32_arm64/file_test.py b/examples/official/9.x/arm32_arm64/file_test.py new file mode 100644 index 0000000..89e2560 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/file_test.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import os +from dbr import * +import dbr +import time + + +def main(): + print('version: ' + dbr.__version__) + BarcodeReader.init_license( + "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") + + reader = BarcodeReader() + reader.init_runtime_settings_with_file( + 'faster.json', conflict_mode=EnumConflictMode.CM_OVERWRITE) + + # read file list + folder = '../../../../images' + target_dir = os.path.join(os.getcwd(), folder) + + if os.path.exists(target_dir): + filelist = os.listdir(target_dir) + + index = 0 + while index < 5: + file = filelist[index] + filapath = os.path.join(target_dir, file) + + if os.path.isfile(filapath): + start_time = time.time() + results = reader.decode_file(filapath) + elapsed_time = time.time() - start_time + + print(filelist[0] + ", elapsed time: " + + str(round(elapsed_time * 1000)) + "ms, ") + if results != None: + for result in results: + print(result.barcode_format_string + + ': ' + result.barcode_text) + else: + print(' results: 0') + + index += 1 + + +if __name__ == '__main__': + main() diff --git a/examples/official/9.x/arm32_arm64/images/0.png b/examples/official/9.x/arm32_arm64/images/0.png new file mode 100644 index 0000000..6671136 Binary files /dev/null and b/examples/official/9.x/arm32_arm64/images/0.png differ diff --git a/examples/official/9.x/arm32_arm64/pillow_test.py b/examples/official/9.x/arm32_arm64/pillow_test.py new file mode 100644 index 0000000..b595153 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/pillow_test.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +import os +from dbr import * +import dbr +import time +from PIL import Image + + +def main(): + print('version: ' + dbr.__version__) + BarcodeReader.init_license( + "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") + + reader = BarcodeReader() + reader.init_runtime_settings_with_file( + 'faster.json', conflict_mode=EnumConflictMode.CM_OVERWRITE) + + # read file list + folder = '../../../../images' + target_dir = os.path.join(os.getcwd(), folder) + print(target_dir) + if os.path.exists(target_dir): + filelist = os.listdir(target_dir) + + index = 0 + while index < len(filelist): + file = filelist[index] + filapath = os.path.join(target_dir, file) + + index += 1 + + if os.path.isfile(filapath): + + with Image.open(filapath) as im: + try: + start_time = time.time() + results = reader.decode_buffer_manually( + im.tobytes(), im.width, im.height, im.width * 3, EnumImagePixelFormat.IPF_RGB_888) + elapsed_time = time.time() - start_time + print(file + ", elapsed time: " + str(round(elapsed_time * + 1000)) + "ms, " + ' results: ' + str(len(results))) + + if results != None: + for result in results: + print(result.barcode_format_string + + ': ' + result.barcode_text) + else: + print(' results: 0') + + except Exception as err: + print(err) + + print('-------------------------------------') + + +if __name__ == '__main__': + main() diff --git a/examples/official/9.x/arm32_arm64/requirements.txt b/examples/official/9.x/arm32_arm64/requirements.txt new file mode 100644 index 0000000..1201155 --- /dev/null +++ b/examples/official/9.x/arm32_arm64/requirements.txt @@ -0,0 +1,3 @@ +dbr +opencv-python +pillow \ No newline at end of file diff --git a/examples/official/9.x/qrcode_template/README.md b/examples/official/9.x/qrcode_template/README.md new file mode 100644 index 0000000..985af3f --- /dev/null +++ b/examples/official/9.x/qrcode_template/README.md @@ -0,0 +1,37 @@ +# Python QR Code Recognition with Dynamsoft Barcode Reader +This repository contains QR code recognition samples using the [Dynamsoft Barcode Reader Python SDK](https://www.dynamsoft.com/barcode-reader/docs/server/programming/python/user-guide.html). + +## Installation +To get started, install the required dependencies: + +```bash +pip install -r requirements.txt +``` + +## Usage +1. Obtain a [30-day FREE trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr) for the Dynamsoft Barcode Reader SDK and save the license key in a `license.txt` file. + +2. Run the sample scripts: + + - `python normal.py` + + ![](https://www.dynamsoft.com/codepool/img/2021/09/qr-color-image-recognition.png) + + - `python inverted-color.py` + + + ![](https://www.dynamsoft.com/codepool/img/2021/09/inverted-qr-speed.jpg) + + - `python perspective-distortion.py` + + ![](https://www.dynamsoft.com/codepool/img/2021/09/qr-perspective-template-decoding.jpg) + + + + + +## Custom Parameters +To fine-tune the parameters for your specific image set, use the [online tool](https://demo.dynamsoft.com/barcode-reader/)。 + +## Blog +[How to Optimize QR Recognition Performance by Image Preprocessing and Parameter Tuning](https://www.dynamsoft.com/codepool/optimize-qr-recognition-performance.html) diff --git a/examples/official/9.x/qrcode_template/inverted-color.json b/examples/official/9.x/qrcode_template/inverted-color.json new file mode 100644 index 0000000..00e9b37 --- /dev/null +++ b/examples/official/9.x/qrcode_template/inverted-color.json @@ -0,0 +1,170 @@ +{ + "ImageParameter": { + "BarcodeColourModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "LightReflection": 1, + "Mode": "BICM_DARK_ON_LIGHT" + } + ], + "BarcodeComplementModes": [ + { + "Mode": "BCM_SKIP" + } + ], + "BarcodeFormatIds": [ + "BF_QR_CODE", + "BF_MICRO_QR" + ], + "BarcodeFormatIds_2": null, + "BinarizationModes": [ + { + "BinarizationThreshold": -1, + "ImagePreprocessingModesIndex": -1, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "BM_THRESHOLD" + } + ], + "ColourClusteringModes": [ + { + "Mode": "CCM_SKIP" + } + ], + "ColourConversionModes": [ + { + "BlueChannelWeight": -1, + "GreenChannelWeight": -1, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "CICM_GENERAL", + "RedChannelWeight": -1 + } + ], + "DPMCodeReadingModes": [ + { + "Mode": "DPMCRM_SKIP" + } + ], + "DeblurLevel": 0, + "DeblurModes": null, + "DeformationResistingModes": [ + { + "Mode": "DRM_SKIP" + } + ], + "Description": "", + "ExpectedBarcodesCount": 0, + "FormatSpecificationNameArray": null, + "GrayscaleTransformationModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "GTM_INVERTED" + } + ], + "ImagePreprocessingModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "IPM_GENERAL" + } + ], + "IntermediateResultSavingMode": { + "Mode": "IRSM_MEMORY" + }, + "IntermediateResultTypes": [ + "IRT_NO_RESULT" + ], + "LocalizationModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "LM_SCAN_DIRECTLY", + "ScanDirection": 0, + "ScanStride": 0 + } + ], + "MaxAlgorithmThreadCount": 4, + "Name": "Settings", + "PDFRasterDPI": 300, + "PDFReadingMode": { + "Mode": "PDFRM_AUTO" + }, + "Pages": "", + "RegionDefinitionNameArray": [ + "Settings" + ], + "RegionPredetectionModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "RPM_GENERAL" + } + ], + "ResultCoordinateType": "RCT_PIXEL", + "ReturnBarcodeZoneClarity": 0, + "ScaleDownThreshold": 2300, + "ScaleUpModes": [ + { + "Mode": "SUM_AUTO" + } + ], + "TerminatePhase": "TP_BARCODE_RECOGNIZED", + "TextAssistedCorrectionMode": { + "BottomTextPercentageSize": 0, + "LeftTextPercentageSize": 0, + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "TACM_VERIFYING", + "RightTextPercentageSize": 0, + "TopTextPercentageSize": 0 + }, + "TextFilterModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "MinImageDimension": 65536, + "Mode": "TFM_GENERAL_CONTOUR", + "Sensitivity": 0 + } + ], + "TextResultOrderModes": [ + { + "Mode": "TROM_CONFIDENCE" + }, + { + "Mode": "TROM_POSITION" + }, + { + "Mode": "TROM_FORMAT" + } + ], + "TextureDetectionModes": [ + { + "LibraryFileName": "", + "LibraryParameters": "", + "Mode": "TDM_GENERAL_WIDTH_CONCENTRATION", + "Sensitivity": 5 + } + ], + "Timeout": 10000 + }, + "RegionDefinition": { + "BarcodeFormatIds": [ + "BF_QR_CODE", + "BF_MICRO_QR" + ], + "BarcodeFormatIds_2": null, + "Bottom": 100, + "ExpectedBarcodesCount": 0, + "FormatSpecificationNameArray": null, + "Left": 0, + "MeasuredByPercentage": 1, + "Name": "Settings", + "Right": 100, + "Top": 0 + }, + "Version": "3.0" + } \ No newline at end of file diff --git a/examples/official/9.x/qrcode_template/inverted-color.py b/examples/official/9.x/qrcode_template/inverted-color.py new file mode 100644 index 0000000..8e8639c --- /dev/null +++ b/examples/official/9.x/qrcode_template/inverted-color.py @@ -0,0 +1,60 @@ +import cv2 +import numpy as np +import time +from dbr import * + +license = "" +with open("license.txt", "r") as f: + license = f.read() + +BarcodeReader.init_license(license) + +reader = BarcodeReader() +error = reader.init_runtime_settings_with_file('inverted-color.json') +print(error) +print(reader.get_runtime_settings().__dict__) +image = cv2.imread('images/inverted-color.jpg') + + +def detect(windowName, image, pixel_format): + try: + buffer = image.tobytes() + height = image.shape[0] + width = image.shape[1] + stride = image.strides[0] + start = time.time() + results = reader.decode_buffer_manually( + buffer, width, height, stride, pixel_format, "") + end = time.time() + print("Time taken: {:.4f}".format(end - start) + " seconds") + + cv2.putText(image, "Time taken: {:.4f}".format( + end - start) + " seconds", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + + if results != None: + for result in results: + print("Barcode Format : ") + print(result.barcode_format_string) + print("Barcode Text : ") + print(result.barcode_text) + + points = result.localization_result.localization_points + data = np.array([[points[0][0], points[0][1]], [points[1][0], points[1][1]], [ + points[2][0], points[2][1]], [points[3][0], points[3][1]]]) + cv2.drawContours(image=image, contours=[ + data], contourIdx=-1, color=(0, 255, 0), thickness=2, lineType=cv2.LINE_AA) + + x = min(points[0][0], points[1][0], points[2][0], points[3][0]) + y = min(points[0][1], points[1][1], points[2][1], points[3][1]) + cv2.putText(image, result.barcode_text, (x, y), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + + cv2.imshow(windowName, image) + except BarcodeReaderError as bre: + print(bre) + + +image_copy = image.copy() +detect('Color', image_copy, EnumImagePixelFormat.IPF_RGB_888) + +cv2.waitKey(0) diff --git a/examples/official/9.x/qrcode_template/license.txt b/examples/official/9.x/qrcode_template/license.txt new file mode 100644 index 0000000..f3b909b --- /dev/null +++ b/examples/official/9.x/qrcode_template/license.txt @@ -0,0 +1 @@ +DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ== \ No newline at end of file diff --git a/examples/official/9.x/qrcode_template/normal.py b/examples/official/9.x/qrcode_template/normal.py new file mode 100644 index 0000000..a12bd20 --- /dev/null +++ b/examples/official/9.x/qrcode_template/normal.py @@ -0,0 +1,73 @@ +import cv2 +import numpy as np +from dbr import * +import time + +license = "" +with open("license.txt", "r") as f: + license = f.read() + +BarcodeReader.init_license(license) + +reader = BarcodeReader() +print(reader.get_runtime_settings().__dict__) +image = cv2.imread('images/normal.jpg') + + +def detect(windowName, image, pixel_format): + try: + buffer = image.tobytes() + height = image.shape[0] + width = image.shape[1] + stride = image.strides[0] + start = time.time() + results = reader.decode_buffer_manually( + buffer, width, height, stride, pixel_format, "") + end = time.time() + print("Time taken: {:.4f}".format(end - start) + " seconds") + + cv2.putText(image, "Time taken: {:.4f}".format( + end - start) + " seconds", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + + if results != None: + for result in results: + print("Barcode Format : ") + print(result.barcode_format_string) + print("Barcode Text : ") + print(result.barcode_text) + + points = result.localization_result.localization_points + data = np.array([[points[0][0], points[0][1]], [points[1][0], points[1][1]], [ + points[2][0], points[2][1]], [points[3][0], points[3][1]]]) + cv2.drawContours(image=image, contours=[ + data], contourIdx=-1, color=(0, 255, 0), thickness=2, lineType=cv2.LINE_AA) + + x = min(points[0][0], points[1][0], points[2][0], points[3][0]) + y = min(points[0][1], points[1][1], points[2][1], points[3][1]) + cv2.putText(image, result.barcode_text, (x, y), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + + cv2.imshow(windowName, image) + except BarcodeReaderError as bre: + print(bre) + + +image_copy = image.copy() +detect('Color', image_copy, EnumImagePixelFormat.IPF_RGB_888) + +grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) +grayscale_image_copy = grayscale_image.copy() +detect('Grayscale', grayscale_image_copy, + EnumImagePixelFormat.IPF_GRAYSCALED) +print('--------------------------------------------------------------') + +blur = cv2.GaussianBlur(grayscale_image, (3, 3), 0) +ret, thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) +print(ret) +binary_image_copy = thresh.copy() +print('--------------------------------------------------------------') + +detect('B&W', binary_image_copy, EnumImagePixelFormat.IPF_GRAYSCALED) +print('--------------------------------------------------------------') + +cv2.waitKey(0) diff --git a/examples/official/9.x/qrcode_template/perspective-distortion.py b/examples/official/9.x/qrcode_template/perspective-distortion.py new file mode 100644 index 0000000..4c5cdc6 --- /dev/null +++ b/examples/official/9.x/qrcode_template/perspective-distortion.py @@ -0,0 +1,58 @@ +import cv2 +import numpy as np +from dbr import * +import time + +license = "" +with open("license.txt", "r") as f: + license = f.read() + +BarcodeReader.init_license(license) + +reader = BarcodeReader() +print(reader.get_runtime_settings().__dict__) +image = cv2.imread('images/perspective-distortion.jpg') + + +def detect(windowName, image, pixel_format): + try: + buffer = image.tobytes() + height = image.shape[0] + width = image.shape[1] + stride = image.strides[0] + start = time.time() + results = reader.decode_buffer_manually( + buffer, width, height, stride, pixel_format, "") + end = time.time() + print("Time taken: {:.4f}".format(end - start) + " seconds") + + cv2.putText(image, "Time taken: {:.4f}".format( + end - start) + " seconds", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + + if results != None: + for result in results: + print("Barcode Format : ") + print(result.barcode_format_string) + print("Barcode Text : ") + print(result.barcode_text) + + points = result.localization_result.localization_points + data = np.array([[points[0][0], points[0][1]], [points[1][0], points[1][1]], [ + points[2][0], points[2][1]], [points[3][0], points[3][1]]]) + cv2.drawContours(image=image, contours=[ + data], contourIdx=-1, color=(0, 255, 0), thickness=2, lineType=cv2.LINE_AA) + + x = min(points[0][0], points[1][0], points[2][0], points[3][0]) + y = min(points[0][1], points[1][1], points[2][1], points[3][1]) + cv2.putText(image, result.barcode_text, (x, y), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + + cv2.imshow(windowName, image) + except BarcodeReaderError as bre: + print(bre) + + +image_copy = image.copy() +detect('Color', image_copy, EnumImagePixelFormat.IPF_RGB_888) + +cv2.waitKey(0) diff --git a/examples/official/9.x/qrcode_template/requirements.txt b/examples/official/9.x/qrcode_template/requirements.txt new file mode 100644 index 0000000..21a096b --- /dev/null +++ b/examples/official/9.x/qrcode_template/requirements.txt @@ -0,0 +1,2 @@ +dbr +opencv-python \ No newline at end of file diff --git a/examples/official/9.x/zxing_zbar/data.py b/examples/official/9.x/zxing_zbar/data.py index 7f0f500..c2f455d 100644 --- a/examples/official/9.x/zxing_zbar/data.py +++ b/examples/official/9.x/zxing_zbar/data.py @@ -7,19 +7,20 @@ # Define cell color red = PatternFill(start_color='FFFF0000', - end_color='FFFF0000', - fill_type='solid') + end_color='FFFF0000', + fill_type='solid') green = PatternFill(start_color='FF00FF00', - end_color='FF00FF00', - fill_type='solid') + end_color='FF00FF00', + fill_type='solid') yellow = PatternFill(start_color='00FFFF00', - end_color='00FFFF00', - fill_type='solid') + end_color='00FFFF00', + fill_type='solid') passed = 'Passed' + def get_workbook(wb_name): if os.path.isfile(wb_name): wb = load_workbook(wb_name) @@ -40,13 +41,17 @@ def get_workbook(wb_name): ws.column_dimensions[utils.get_column_letter(5)].width = 20 return wb + def save_workbook(wb, wb_name): if wb != None: wb.save(wb_name) + def append_row(wb, filename=None, expected_results=None, zbar_results=None, dbr_results=None, ZXing_results=None): ws = wb.active - ws.append([filename, expected_results, zbar_results, dbr_results, ZXing_results]) + ws.append([filename, expected_results, + zbar_results, dbr_results, ZXing_results]) + def update_row(wb, row_index, filename=None, expected_results=None, zbar_results=None, dbr_results=None, ZXing_results=None): ws = wb.active @@ -74,24 +79,10 @@ def update_row(wb, row_index, filename=None, expected_results=None, zbar_results else: row[4].fill = red + def set_recognition_rate(wb, row_index, r1=None, r2=None, r3=None): ws = wb.active row = ws[row_index] row[2].value = r1 row[3].value = r2 row[4].value = r3 - - -# Test -# name = 'data.xlsx' -# wb = get_workbook(name) -# ws = wb.active -# index = 2 -# update_row(wb, index, r'D:\python-zxing-zbar-dbr\dataset\20499525_2.jpg', '20499525', '20499525', '20499525', '20499521') -# index += 1 -# set_recognition_rate(wb, index, '59.46%', '75.68%', '13.51%') -# save_workbook(wb, name) - - - - diff --git a/examples/official/9.x/zxing_zbar/dataset/2152663000991_1.jpg b/examples/official/9.x/zxing_zbar/dataset/2152663000991_1.jpg deleted file mode 100644 index b966b2c..0000000 Binary files a/examples/official/9.x/zxing_zbar/dataset/2152663000991_1.jpg and /dev/null differ diff --git a/examples/official/9.x/zxing_zbar/dataset/2165742004797_1.jpg b/examples/official/9.x/zxing_zbar/dataset/2165742004797_1.jpg deleted file mode 100644 index c26c6b9..0000000 Binary files a/examples/official/9.x/zxing_zbar/dataset/2165742004797_1.jpg and /dev/null differ diff --git a/examples/official/9.x/zxing_zbar/dataset/2233400002673_2.jpg b/examples/official/9.x/zxing_zbar/dataset/2233400002673_2.jpg deleted file mode 100644 index b698f41..0000000 Binary files a/examples/official/9.x/zxing_zbar/dataset/2233400002673_2.jpg and /dev/null differ diff --git a/examples/official/9.x/zxing_zbar/dataset/2259797018677_1.jpg b/examples/official/9.x/zxing_zbar/dataset/2259797018677_1.jpg deleted file mode 100644 index c4c72b3..0000000 Binary files a/examples/official/9.x/zxing_zbar/dataset/2259797018677_1.jpg and /dev/null differ diff --git a/examples/official/9.x/zxing_zbar/dataset/2275104045655_1.jpg b/examples/official/9.x/zxing_zbar/dataset/2275104045655_1.jpg deleted file mode 100644 index c742dd2..0000000 Binary files a/examples/official/9.x/zxing_zbar/dataset/2275104045655_1.jpg and /dev/null differ diff --git a/examples/official/9.x/zxing_zbar/dataset/2294875026113_1.jpg b/examples/official/9.x/zxing_zbar/dataset/2294875026113_1.jpg deleted file mode 100644 index ab3f591..0000000 Binary files a/examples/official/9.x/zxing_zbar/dataset/2294875026113_1.jpg and /dev/null differ diff --git a/examples/official/9.x/zxing_zbar/requirements.txt b/examples/official/9.x/zxing_zbar/requirements.txt index 7f4b3a0..18a8208 100644 --- a/examples/official/9.x/zxing_zbar/requirements.txt +++ b/examples/official/9.x/zxing_zbar/requirements.txt @@ -1,4 +1,5 @@ dbr pyzbar zxing-cpp -openpyxl \ No newline at end of file +openpyxl +opencv-python \ No newline at end of file diff --git a/examples/ui/app.py b/examples/ui/app.py index b2d32cb..be06d20 100644 --- a/examples/ui/app.py +++ b/examples/ui/app.py @@ -1,41 +1,46 @@ + from tkinter import * import os import json import sys -import barcodeQrSDK +package_path = os.path.join(os.path.dirname(__file__), '../../') +sys.path.append(package_path) + +import barcodeQrSDK # set license -barcodeQrSDK.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") +barcodeQrSDK.initLicense( + "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") # initialize barcode reader reader = barcodeQrSDK.createInstance() + def showResults(results, barcode_image): ws = Tk() ws.title('Barcode Reader') - - bg = PhotoImage(file = barcode_image) + bg = PhotoImage(file=barcode_image) ws.geometry('{}x{}'.format(bg.width(), bg.height())) canvas = Canvas( - ws, - width = bg.width(), - height = bg.height() - ) - - canvas.pack(fill='both', expand = True) + ws, + width=bg.width(), + height=bg.height() + ) + + canvas.pack(fill='both', expand=True) canvas.create_image( - 0, - 0, + 0, + 0, image=bg, - anchor = "nw" - ) - + anchor="nw" + ) + for result in results: print("barcode format: " + result.format) print("barcode value: " + result.text) - + x1 = result.x1 y1 = result.y1 x2 = result.x2 @@ -44,17 +49,18 @@ def showResults(results, barcode_image): y3 = result.y3 x4 = result.x4 y4 = result.y4 - - canvas.create_text(x1 + 10, y1 + 10, text = result.text, font=('Arial', 18), fill='red') - + + canvas.create_text(x1 + 10, y1 + 10, text=result.text, + font=('Arial', 18), fill='red') + canvas.create_line(x1, y1, x2, y2, fill='red', width=2) canvas.create_line(x2, y2, x3, y3, fill='red', width=2) canvas.create_line(x3, y3, x4, y4, fill='red', width=2) canvas.create_line(x4, y4, x1, y1, fill='red', width=2) - ws.mainloop() + def decodeFile(fileName): try: results, elapsed_time = reader.decodeFile(fileName) @@ -63,9 +69,10 @@ def decodeFile(fileName): print(err) return None + if __name__ == "__main__": import sys - barcode_image = "test.png" + barcode_image = "../../images/test.png" params = reader.getParameters() # Convert string to JSON object json_obj = json.loads(params) @@ -80,6 +87,3 @@ def decodeFile(fileName): results = decodeFile(barcode_image) if results is not None: showResults(results, barcode_image) - - - diff --git a/examples/official/9.x/zxing_zbar/dataset/1040000062669_1.jpg b/images/dataset/1040000062669_1.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/1040000062669_1.jpg rename to images/dataset/1040000062669_1.jpg diff --git a/examples/official/9.x/zxing_zbar/dataset/2000700048829_1.jpg b/images/dataset/2000700048829_1.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/2000700048829_1.jpg rename to images/dataset/2000700048829_1.jpg diff --git a/examples/official/9.x/zxing_zbar/dataset/2010945099999_2.jpg b/images/dataset/2010945099999_2.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/2010945099999_2.jpg rename to images/dataset/2010945099999_2.jpg diff --git a/examples/official/9.x/zxing_zbar/dataset/20499525_2.jpg b/images/dataset/20499525_2.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/20499525_2.jpg rename to images/dataset/20499525_2.jpg diff --git a/examples/official/9.x/zxing_zbar/dataset/20665913_2.jpg b/images/dataset/20665913_2.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/20665913_2.jpg rename to images/dataset/20665913_2.jpg diff --git a/examples/official/9.x/zxing_zbar/dataset/57023397_2.jpg b/images/dataset/57023397_2.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/57023397_2.jpg rename to images/dataset/57023397_2.jpg diff --git a/examples/official/9.x/zxing_zbar/dataset/80787174_2.jpg b/images/dataset/80787174_2.jpg similarity index 100% rename from examples/official/9.x/zxing_zbar/dataset/80787174_2.jpg rename to images/dataset/80787174_2.jpg diff --git a/images/inverted-color.jpg b/images/inverted-color.jpg new file mode 100644 index 0000000..2bb58f7 Binary files /dev/null and b/images/inverted-color.jpg differ diff --git a/images/normal.jpg b/images/normal.jpg new file mode 100644 index 0000000..c6fa806 Binary files /dev/null and b/images/normal.jpg differ diff --git a/images/perspective-distortion.jpg b/images/perspective-distortion.jpg new file mode 100644 index 0000000..4657d41 Binary files /dev/null and b/images/perspective-distortion.jpg differ diff --git a/examples/ui/test.png b/images/test.png similarity index 100% rename from examples/ui/test.png rename to images/test.png diff --git a/setup.py b/setup.py index f823c9e..0ee725f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ packages = ['barcodeQrSDK'] setup(name='barcode-qr-code-sdk', - version='9.6.40', + version='9.6.40.1', description='Barcode and QR code scanning SDK for Python', long_description=long_description, long_description_content_type="text/markdown", diff --git a/setup_setuptools.py b/setup_setuptools.py index a07a1b4..99b680d 100644 --- a/setup_setuptools.py +++ b/setup_setuptools.py @@ -97,7 +97,7 @@ def run(self): setup(name='barcode-qr-code-sdk', - version='9.6.40', + version='9.6.40.1', description='Barcode and QR code scanning SDK for Python', long_description=long_description, long_description_content_type="text/markdown", diff --git a/test.png b/test.png deleted file mode 100644 index 97b9391..0000000 Binary files a/test.png and /dev/null differ diff --git a/test.py b/test.py index da77823..53861b9 100644 --- a/test.py +++ b/test.py @@ -2,6 +2,7 @@ import barcodeQrSDK from time import sleep +file_path = "images/test.png" # set license ret = barcodeQrSDK.initLicense( "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") @@ -19,7 +20,7 @@ print(ret) # decodeFile() -results, elapsed_time = reader.decodeFile("test.png") +results, elapsed_time = reader.decodeFile(file_path) print('Elapsed time: ' + str(elapsed_time) + 'ms') for result in results: print(result.format) @@ -34,7 +35,7 @@ print(result.y4) # decodeMat() -image = cv2.imread("test.png") +image = cv2.imread(file_path) results, elapsed_time = reader.decodeMat(image) print('Elapsed time: ' + str(elapsed_time) + 'ms') for result in results: @@ -69,7 +70,7 @@ def callback(results, elapsed_time): print(result.y4) -image = cv2.imread("test.png") +image = cv2.imread(file_path) reader.addAsyncListener(callback) reader.decodeMatAsync(image) sleep(1)