diff --git a/Legal.txt b/Legal.txt index 6a8dadf..3b37ed0 100644 --- a/Legal.txt +++ b/Legal.txt @@ -124,55 +124,85 @@ but is also freely distributable. LibPNG -This copy of the libpng notices is provided for your convenience. In case of -any discrepancy between this copy and the notices in the file png.h that is -included in the libpng distribution, the latter shall prevail. +COPYRIGHT NOTICE, DISCLAIMER, and LICENSE +========================================= -COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: +PNG Reference Library License version 2 +--------------------------------------- -If you modify libpng you may insert additional notices immediately following -this sentence. + * Copyright (c) 1995-2023 The PNG Reference Library Authors. + * Copyright (c) 2018-2023 Cosmin Truta. + * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson. + * Copyright (c) 1996-1997 Andreas Dilger. + * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. -This code is released under the libpng license. +The software is supplied "as is", without warranty of any kind, +express or implied, including, without limitation, the warranties +of merchantability, fitness for a particular purpose, title, and +non-infringement. In no event shall the Copyright owners, or +anyone distributing the software, be liable for any damages or +other liability, whether in contract, tort or otherwise, arising +from, out of, or in connection with the software, or the use or +other dealings in the software, even if advised of the possibility +of such damage. -libpng versions 1.0.7, July 1, 2000 through 1.6.32, August 24, 2017 are -Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are +Permission is hereby granted to use, copy, modify, and distribute +this software, or portions hereof, for any purpose, without fee, +subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you + must not claim that you wrote the original software. If you + use this software in a product, an acknowledgment in the product + documentation would be appreciated, but is not required. + + 2. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 3. This Copyright notice may not be removed or altered from any + source or altered source distribution. + + +PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35) +----------------------------------------------------------------------- + +libpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are +Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are derived from libpng-1.0.6, and are distributed according to the same disclaimer and license as libpng-1.0.6 with the following individuals added to the list of Contributing Authors: - Simon-Pierre Cadieux - Eric S. Raymond - Mans Rullgard - Cosmin Truta - Gilles Vollant - James Yu - Mandar Sahastrabuddhe - Google Inc. - Vadim Barkov + Simon-Pierre Cadieux + Eric S. Raymond + Mans Rullgard + Cosmin Truta + Gilles Vollant + James Yu + Mandar Sahastrabuddhe + Google Inc. + Vadim Barkov and with the following additions to the disclaimer: - There is no warranty against interference with your enjoyment of the - library or against infringement. There is no warranty that our - efforts or the library will fulfill any of your particular purposes - or needs. This library is provided with all faults, and the entire - risk of satisfactory quality, performance, accuracy, and effort is with - the user. + There is no warranty against interference with your enjoyment of + the library or against infringement. There is no warranty that our + efforts or the library will fulfill any of your particular purposes + or needs. This library is provided with all faults, and the entire + risk of satisfactory quality, performance, accuracy, and effort is + with the user. Some files in the "contrib" directory and some configure-generated -files that are distributed with libpng have other copyright owners and +files that are distributed with libpng have other copyright owners, and are released under other open source licenses. libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from libpng-0.96, and are distributed according to the same disclaimer and -license as libpng-0.96, with the following individuals added to the list -of Contributing Authors: +license as libpng-0.96, with the following individuals added to the +list of Contributing Authors: - Tom Lane - Glenn Randers-Pehrson - Willem van Schaik + Tom Lane + Glenn Randers-Pehrson + Willem van Schaik libpng versions 0.89, June 1996, through 0.96, May 1997, are Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88, @@ -180,14 +210,14 @@ and are distributed according to the same disclaimer and license as libpng-0.88, with the following individuals added to the list of Contributing Authors: - John Bowler - Kevin Bracey - Sam Bushell - Magnus Holmgren - Greg Roelofs - Tom Tanner + John Bowler + Kevin Bracey + Sam Bushell + Magnus Holmgren + Greg Roelofs + Tom Tanner -Some files in the "scripts" directory have other copyright owners +Some files in the "scripts" directory have other copyright owners, but are released under this license. libpng versions 0.5, May 1995, through 0.88, January 1996, are @@ -196,66 +226,38 @@ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. For the purposes of this copyright and license, "Contributing Authors" is defined as the following set of individuals: - Andreas Dilger - Dave Martindale - Guy Eric Schalnat - Paul Schmidt - Tim Wegner - -The PNG Reference Library is supplied "AS IS". The Contributing Authors -and Group 42, Inc. disclaim all warranties, expressed or implied, -including, without limitation, the warranties of merchantability and of -fitness for any purpose. The Contributing Authors and Group 42, Inc. -assume no liability for direct, indirect, incidental, special, exemplary, -or consequential damages, which may result from the use of the PNG -Reference Library, even if advised of the possibility of such damage. + Andreas Dilger + Dave Martindale + Guy Eric Schalnat + Paul Schmidt + Tim Wegner + +The PNG Reference Library is supplied "AS IS". The Contributing +Authors and Group 42, Inc. disclaim all warranties, expressed or +implied, including, without limitation, the warranties of +merchantability and of fitness for any purpose. The Contributing +Authors and Group 42, Inc. assume no liability for direct, indirect, +incidental, special, exemplary, or consequential damages, which may +result from the use of the PNG Reference Library, even if advised of +the possibility of such damage. Permission is hereby granted to use, copy, modify, and distribute this source code, or portions hereof, for any purpose, without fee, subject to the following restrictions: - 1. The origin of this source code must not be misrepresented. - - 2. Altered versions must be plainly marked as such and must not - be misrepresented as being the original source. - - 3. This Copyright notice may not be removed or altered from any - source or altered source distribution. - -The Contributing Authors and Group 42, Inc. specifically permit, without -fee, and encourage the use of this source code as a component to -supporting the PNG file format in commercial products. If you use this -source code in a product, acknowledgment is not required but would be -appreciated. - -END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE. - -TRADEMARK: - -The name "libpng" has not been registered by the Copyright owner -as a trademark in any jurisdiction. However, because libpng has -been distributed and maintained world-wide, continually since 1995, -the Copyright owner claims "common-law trademark protection" in any -jurisdiction where common-law trademark is recognized. - -OSI CERTIFICATION: + 1. The origin of this source code must not be misrepresented. -Libpng is OSI Certified Open Source Software. OSI Certified Open Source is -a certification mark of the Open Source Initiative. OSI has not addressed -the additional disclaimers inserted at version 1.0.7. + 2. Altered versions must be plainly marked as such and must not + be misrepresented as being the original source. -EXPORT CONTROL: + 3. This Copyright notice may not be removed or altered from any + source or altered source distribution. -The Copyright owner believes that the Export Control Classification -Number (ECCN) for libpng is EAR99, which means not subject to export -controls or International Traffic in Arms Regulations (ITAR) because -it is open source, publicly available software, that does not contain -any encryption software. See the EAR, paragraphs 734.3(b)(3) and -734.7(b). - -Glenn Randers-Pehrson -glennrp at users.sourceforge.net -April 1, 2017 +The Contributing Authors and Group 42, Inc. specifically permit, +without fee, and encourage the use of this source code as a component +to supporting the PNG file format in commercial products. If you use +this source code in a product, acknowledgment is not required but would +be appreciated. =================================================================================== @@ -495,28 +497,20 @@ limitations under the License. =================================================================================== -OpenCV +OpenCV 4.5.2 + -License Agreement -For Open Source Computer Vision Library -(3-clause BSD License) +Copyright 2022, OpenCV Foundation -Copyright (C) 2000-2015, Intel Corporation, all rights reserved. -Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. -Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. -Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. -Copyright (C) 2015, OpenCV Foundation, all rights reserved. -Copyright (C) 2015, Itseez Inc., all rights reserved. -Third party copyrights are property of their respective owners. + -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the names of the copyright holders nor the names of the contributors may be used to endorse or promote products derived from this software without specific prior written permission. +http://www.apache.org/licenses/LICENSE-2.0 -This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall copyright holders or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of -the use of this software, even if advised of the possibility of such damage. + + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =================================================================================== @@ -739,8 +733,92 @@ OpenSSL * copied and put under another distribution licence * [including the GNU Public Licence.] */ +=================================================================================== + + + +=================================================================================== +openjpeg Library + +The copyright in this software is being made available under the 2-clauses +BSD License, included below. This software may be subject to other third +party and contributor rights, including patent rights, and no such rights +are granted under this license. + +Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium +Copyright (c) 2002-2014, Professor Benoit Macq +Copyright (c) 2003-2014, Antonin Descampe +Copyright (c) 2003-2009, Francois-Olivier Devaux +Copyright (c) 2005, Herve Drolon, FreeImage Team +Copyright (c) 2002-2003, Yannick Verschueren +Copyright (c) 2001-2003, David Janssens +Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France +Copyright (c) 2012, CS Systemes d'Information, France + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +=================================================================================== + + =================================================================================== +jbig2enc Library + +Copyright 2006 Google Inc. All Rights Reserved. +Author: agl@imperialviolet.org (Adam Langley) + +Copyright (C) 2006 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +=================================================================================== + + + +=================================================================================== +PDFWriter + +Copyright 2011 Gal Kahana PDFWriter +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License.  +You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0  +Unless required by applicable law or agreed to in writing, software  +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +=================================================================================== + =================================================================================== diff --git a/README.md b/README.md index 68d9c34..8883f70 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Dynamsoft Barcode Reader samples for Python edition +# Dynamsoft Barcode Reader Samples for Python Edition -[![Current version number](https://img.shields.io/pypi/v/dbr?color=orange)](https://pypi.org/project/dbr/) -[![Supported Python versions](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/downloads/) -[![PyPI downloads](https://img.shields.io/pypi/dm/dbr)](https://pypistats.org/packages/dbr) +[![Current version number](https://img.shields.io/pypi/v/dynamsoft_barcode_reader_bundle?color=orange)](https://pypi.org/project/dynamsoft_barcode_reader_bundle/) +[![Supported Python versions](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/downloads/) +[![PyPI downloads](https://img.shields.io/pypi/dm/dynamsoft_barcode_reader_bundle)](https://pypistats.org/packages/dynamsoft_barcode_reader_bundle) ![Dynamsoft](https://dynamsoft.github.io/styleguide/assets/images/icons/dynamsoft_logos/dynamsoft_logo_original.png "Dynamsoft") @@ -14,45 +14,35 @@ This repository contains multiple samples that demonstrate how to use the [Dynam ### Supported Platforms - Windows x64 -- Linux (x64, ARM32, ARM64) +- Linux (x64, 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 +- Python 3.11 +- Python 3.10 +- Python 3.9 +- Python 3.8 ## Installation ``` -pip install dbr +pip install dynamsoft_barcode_reader_bundle ``` or ``` -pip3 install dbr +pip3 install dynamsoft_barcode_reader_bundle ``` ## Samples | Sample Name | Description | | ----------- | ----------- | -| [`hello-world`](samples/hello-world.py) | Shows the simplest way to recognize barcodes from images in Python using Dynamsoft Barcode Reader SDK. | -| [`general-settings`](samples/general-settings.py) | Shows how to adjust general scan settings, e.g., barcode format, barcode count, scan region. | -| [`image-decoding`](samples/image-decoding.py) | Shows how to decode images in various formats, e.g., file bytes, opencv image, raw image buffer. | -| [`video-decoding`](samples/video-decoding.py) | Shows how to decode barcodes from a video from a file or camera. | -| [`video-decoding-for-picamera`](samples/video-decoding-for-picamera.py) | Shows how to scan barcodes from videos from a Raspberry Pi camera (PiCamera). | -| [`batch-decode`](samples/performance/batch-decode.py) | Shows how to batch decode image files from a specified folder. | -| [`speed-first-settings`](samples/performance/speed-first-settings.py) | Shows how to configure the scan settings for best barcode reading speed. | -| [`read-rate-first-settings`](samples/performance/read-rate-first-settings.py) | 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`](samples/performance/accuracy-first-settings.py) | Shows how to configure the scan settings for best barcode reading accuracy. | -| [`read-dpm-barcode`](samples/use-case/read-dpm-barcode.py) | Shows how to read DPM (Direct Part Mark) barcodes. | +| [`ReadAnImage`](Samples/read_an_image.py) | Shows the simplest way to read barcodes from an image file and output barcode format and text. | +| [`ReadMultipleImages`](Samples/read_multiple_images.py) | Shows the simplest way to read barcodes from directory with image files and output barcode format and text. | ## Documentation @@ -60,9 +50,9 @@ https://www.dynamsoft.com/barcode-reader/docs/server/programming/python/?ver=lat ## 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. +The library requires a license to work, you use the API `LicenseManager.init_license` to initialize 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. +These samples use a free public trial license which require network connection to function. You can request a 30-day free trial license via the Request a Trial License link which works offline. ## Contact Us diff --git a/Samples/read_an_image.py b/Samples/read_an_image.py new file mode 100644 index 0000000..0dbe372 --- /dev/null +++ b/Samples/read_an_image.py @@ -0,0 +1,26 @@ +from dynamsoft_barcode_reader_bundle import * +import os + +if __name__ == '__main__': + # Initialize license. + # You can request and extend a trial license from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=python + # The string 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' here is a free public trial license. Note that network connection is required for this license to work. + errorCode, errorMsg = LicenseManager.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") + if errorCode != EnumErrorCode.EC_OK and errorCode != EnumErrorCode.EC_LICENSE_CACHE_USED: + print("License initialization failed: ErrorCode:", errorCode, ", ErrorString:", errorMsg) + else: + cvr = CaptureVisionRouter() + result = cvr.capture("../Images/GeneralBarcodes.png", EnumPresetTemplate.PT_READ_BARCODES.value) + if result.get_error_code() != EnumErrorCode.EC_OK: + print("Error:", result.get_error_code(), result.get_error_string()) + barcode_result = result.get_decoded_barcodes_result() + if barcode_result is None or barcode_result.get_items() == 0: + print("No barcode detected.") + else: + items = barcode_result.get_items() + print("Decoded", len(items), "barcodes.") + for index,item in enumerate(items): + print("Result", index+1) + print("Barcode Format:", item.get_format_string()) + print("Barcode Text:", item.get_text()) + input("Press Enter to quit...") \ No newline at end of file diff --git a/Samples/read_multiple_images.py b/Samples/read_multiple_images.py new file mode 100644 index 0000000..78a25c2 --- /dev/null +++ b/Samples/read_multiple_images.py @@ -0,0 +1,53 @@ +from dynamsoft_barcode_reader_bundle import * +import os + +class MyCapturedResultReceiver(CapturedResultReceiver): + + def __init__(self) -> None: + super().__init__() + def on_decoded_barcodes_received(self, result: "DecodedBarcodesResult") -> None: + tag = result.get_original_image_tag() + if isinstance(tag, FileImageTag): + print("File:", tag.get_file_path()) + if result.get_error_code() != EnumErrorCode.EC_OK: + print("Error:", result.get_error_string()) + else: + items = result.get_items() + print("Detected", len(items), "barcodes.") + for index, item in enumerate(items): + print("Result", index+1) + print("Barcode Format:", item.get_format_string()) + print("Barcode Text:", item.get_text()) + +class MyImageSourceStateListener(ImageSourceStateListener): + def __init__(self, cvr:CaptureVisionRouter) -> None: + super().__init__() + self.cvr = cvr + def on_image_source_state_received(self, state: int) -> None: + if state == EnumImageSourceState.ISS_EXHAUSTED: + if self.cvr != None: + self.cvr.stop_capturing() +if __name__ == '__main__': + # Initialize license. + # You can request and extend a trial license from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=python + # The string 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' here is a free public trial license. Note that network connection is required for this license to work. + errorCode, errorMsg = LicenseManager.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") + if errorCode != EnumErrorCode.EC_OK and errorCode != EnumErrorCode.EC_LICENSE_CACHE_USED: + print("License initialization failed: ErrorCode:", errorCode, ", ErrorString:", errorMsg) + else: + cvr = CaptureVisionRouter() + + fetcher = DirectoryFetcher() + fetcher.set_directory("../Images") + cvr.set_input(fetcher) + + receiver = MyCapturedResultReceiver() + cvr.add_result_receiver(receiver) + + listener = MyImageSourceStateListener(cvr) + cvr.add_image_source_state_listener(listener) + + errorCode, errorMsg = cvr.start_capturing("", True) + if errorCode != EnumErrorCode.EC_OK: + print("error:", errorMsg) + input("Press Enter to quit...") \ No newline at end of file diff --git a/images/AllSupportedBarcodeTypes.png b/images/AllSupportedBarcodeTypes.png deleted file mode 100644 index a0a6817..0000000 Binary files a/images/AllSupportedBarcodeTypes.png and /dev/null differ diff --git a/images/Codabar1.jpg b/images/Codabar1.jpg deleted file mode 100644 index aaa4eeb..0000000 Binary files a/images/Codabar1.jpg and /dev/null differ diff --git a/images/GS1 DataBar.png b/images/GS1 DataBar.png new file mode 100644 index 0000000..4b8510f Binary files /dev/null and b/images/GS1 DataBar.png differ diff --git a/images/GeneralBarcodes.png b/images/GeneralBarcodes.png new file mode 100644 index 0000000..9c21889 Binary files /dev/null and b/images/GeneralBarcodes.png differ diff --git a/images/PatchCode.png b/images/PatchCode.png new file mode 100644 index 0000000..7a5c128 Binary files /dev/null and b/images/PatchCode.png differ diff --git a/images/Pharmacode.png b/images/Pharmacode.png new file mode 100644 index 0000000..fd15dd0 Binary files /dev/null and b/images/Pharmacode.png differ diff --git a/images/PostalCode.png b/images/PostalCode.png new file mode 100644 index 0000000..ba44533 Binary files /dev/null and b/images/PostalCode.png differ diff --git a/images/codabar.jpg b/images/codabar.jpg index 9dc3c5b..aaa4eeb 100644 Binary files a/images/codabar.jpg and b/images/codabar.jpg differ diff --git a/images/dpm.jpg b/images/dpm.jpg deleted file mode 100644 index 3dfc0de..0000000 Binary files a/images/dpm.jpg and /dev/null differ diff --git a/samples/general-settings.py b/samples/general-settings.py deleted file mode 100644 index 879932e..0000000 --- a/samples/general-settings.py +++ /dev/null @@ -1,65 +0,0 @@ -import os -from dbr import * - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - reader = BarcodeReader.get_instance() - if reader == None: - raise BarcodeReaderError("Get instance failed") - # There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template. - # 3. General settings (including barcode format, barcode count and scan region) through PublicRuntimeSettings - # 3.1 Obtain current runtime settings of instance. - settings = reader.get_runtime_settings() - - # 3.2 Set the expected barcode format you want to read. - # The barcode format our library will search for is composed of BarcodeFormat group 1 and BarcodeFormat group 2. - # So you need to specify the barcode format in group 1 and group 2 individually. - settings.barcode_format_ids = EnumBarcodeFormat.BF_ALL - settings.barcode_format_ids_2 = EnumBarcodeFormat_2.BF2_POSTALCODE | EnumBarcodeFormat_2.BF2_DOTCODE - - # 3.3 Set the expected barcode count you want to read. - settings.expected_barcodes_count = 10 - - # 3.4 Set the ROI(region of interest) to speed up the barcode reading process. - # Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point. - settings.region_measured_by_percentage = 1 - settings.region_left = 0 - settings.region_right = 100 - settings.region_top = 0 - settings.region_bottom = 100 - - # 3.5 Apply the new settings to the instance - reader.update_runtime_settings(settings) - - # 3. General settings (including barcode format, barcode count and scan region) through parameters template. - # reader.init_runtime_settings_with_string("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"ExpectedBarcodesCount\":10,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}") - - # Replace by your own image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/AllSupportedBarcodeTypes.png" - - # 4.Decode barcodes from an image file. - results = reader.decode_file(image_path) - - # 5.Output the barcode text. - if results != None: - i = 0 - for text_result in results: - print("Barcode " + str(i)) - print("Barcode Format : " + text_result.barcode_format_string) - print("Barcode Text : " + text_result.barcode_text) - i = i+1 - else: - print("No data detected.") - - # 6.Release resource - reader.recycle_instance() - except BarcodeReaderError as bre: - print(bre) diff --git a/samples/hello-world.py b/samples/hello-world.py deleted file mode 100644 index 55628cc..0000000 --- a/samples/hello-world.py +++ /dev/null @@ -1,31 +0,0 @@ -import os -from dbr import * - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - dbr = BarcodeReader() - - # Replace by your own image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/AllSupportedBarcodeTypes.png" - - # 3.Decode barcodes from an image file. - results = dbr.decode_file(image_path) - - # 4.Output the barcode text. - if results != None: - i = 0 - for res in results: - print("Barcode " + str(i) + ":" + res.barcode_text) - i = i+1 - else: - print("No data detected.") - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/image-decoding.py b/samples/image-decoding.py deleted file mode 100644 index 5639808..0000000 --- a/samples/image-decoding.py +++ /dev/null @@ -1,94 +0,0 @@ -import os -import sys -from dbr import * -import cv2 - -def choose_number() -> int: - print() - print(">> Choose a number for different decoding interfaces:") - print(" 0: exit program") - print(" 1: decode_file") - print(" 2: decode_file_stream") - print(" 3: decode_buffer") - print(" 4: decode_buffer_manually") - - choose_num = -1 - line = sys.stdin.readline() - - try: - choose_num = int(line) - except Exception as exp: - print(exp) - - return choose_num - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - dbr = BarcodeReader.get_instance() - if dbr == None : - raise BarcodeReaderError("Get instance failed") - - # Replace by your own image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/AllSupportedBarcodeTypes.png" - - while True: - while True: - num = choose_number() - if num < 0 or num > 4: - print("Please choose a valid number.") - else: - break - - results = None - - # 3.Decode barcodes from an image file. - if num == 0: - # exit program - break - elif num == 1: - # 3.1 Decoding with file - results = dbr.decode_file(image_path) - elif num == 2: - # 3.2 Decoding with file bytes array - with open(image_path,"rb") as f: - bytes = f.read() - - results = dbr.decode_file_stream(bytearray(bytes)) - elif num == 3: - # 3.3 Decoding with opencv image - cv_buffer = cv2.imread(image_path) - - results = dbr.decode_buffer(cv_buffer) - elif num == 4: - # 3.4 Decoding with buffer manually - cv_buffer = cv2.imread(image_path) - buffer = cv_buffer.tobytes() - height = cv_buffer.shape[0] - width = cv_buffer.shape[1] - stride = cv_buffer.strides[0] - - results = dbr.decode_buffer_manually(buffer, width, height, stride, EnumImagePixelFormat.IPF_RGB_888) - else: - break - - # 4.Output the barcode text. - if results != None: - i = 0 - for res in results: - barcode_format = res.barcode_format_string - - print("Barcode " + str(i) + ":" + barcode_format + "," + res.barcode_text) - i = i+1 - else: - print("No data detected.") - dbr.recycle_instance() - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/performance/accuracy-first-settings.py b/samples/performance/accuracy-first-settings.py deleted file mode 100644 index 2cf0cf5..0000000 --- a/samples/performance/accuracy-first-settings.py +++ /dev/null @@ -1,88 +0,0 @@ -import os -from dbr import * - -def config_accuracy_first(dbr:BarcodeReader): - - # Obtain current runtime settings of instance. - sts = dbr.get_runtime_settings() - - # 1. Set expected barcode format - # The more precise the barcode format is set, the higher the accuracy. - # Mostly, misreading only occurs on reading oneD barcode. So here we use OneD barcode format to demonstrate. - sts.barcode_format_ids = EnumBarcodeFormat.BF_ONED - sts.barcode_format_ids_2 = EnumBarcodeFormat.BF_NULL - - # 2. Set the minimal result confidence. - # The greater the confidence, the higher the accuracy. - # Filter by minimal confidence of the decoded barcode. We recommend using 30 as the default minimal confidence value - sts.minResultConfidence = 30 - - # 3. Sets the minimum length of barcode text for filtering. - # The more precise the barcode text length is set, the higher the accuracy. - sts.minBarcodeTextLength = 6 - - # Apply the new settings to the instance - dbr.update_runtime_settings(sts) - -def config_accuracy_first_by_template(dbr:BarcodeReader): - # Compared with PublicRuntimeSettings, parameter templates have a richer ability to control parameter details. - # Please refer to the parameter explanation in "accuracy-first-template.json" to understand how to control accuracy first. - template_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "accuracy-first-template.json" - error = dbr.init_runtime_settings_with_file(template_path, EnumConflictMode.CM_OVERWRITE) - if error[0] != EnumErrorCode.DBR_OK: - print("init_runtime_settings_with_file error: " + error[1]) - -def output_results(results:TextResult): - if results != None: - i = 0 - for res in results: - barcode_format = res.barcode_format_string - - print("Barcode " + str(i) + ":" + barcode_format + "," + res.barcode_text) - i = i+1 - else: - print("No data detected.") - - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - dbr = BarcodeReader.get_instance() - if dbr == None: - raise BarcodeReaderError("Get instance failed") - # Replace by your own image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../../images/AllSupportedBarcodeTypes.png" - - # Accuracy = The number of correctly decoded barcodes/the number of all decoded barcodes - # There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template. - print("Decode through PublicRuntimeSettings:") - - # 3.a config through PublicRuntimeSettings - config_accuracy_first(dbr) - - # 4.a Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings. - results = dbr.decode_file(image_path,"") - - # 5.a Output the barcode format and barcode text. - output_results(results) - - print("\nDecode through parameters template:") - # 3.b config through parameters template - config_accuracy_first_by_template(dbr) - - # 4.b Decode barcodes from an image file by template. - results = dbr.decode_file(image_path, "") - - # 5.b Output the barcode format and barcode text. - output_results(results) - - dbr.recycle_instance() - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/performance/accuracy-first-template.json b/samples/performance/accuracy-first-template.json deleted file mode 100644 index c0a9755..0000000 --- a/samples/performance/accuracy-first-template.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "ImageParameter" : { - "Name" : "tpl_afs", - "BarcodeFormatIds" : [ "BF_ONED" ], - "BarcodeFormatIds_2" : null, - "FormatSpecificationNameArray" : ["FS_Filter"] - }, - "FormatSpecificationArray": [{ - "Name": "FS_Filter", - "ModuleSizeRangeArray": [ - { - "MinValue": 2, - "MaxValue": 20 - } - ], - "BarcodeTextLengthRangeArray" : [ - { - "MaxValue" : 20, - "MinValue" : 6 - } - ], - "MinResultConfidence" : 30, - "BarcodeTextRegExPattern" : "^[a-zA-Z0-9]+$" - }], - "Version" : "3.0" -} diff --git a/samples/performance/batch-decode.py b/samples/performance/batch-decode.py deleted file mode 100644 index b8bb296..0000000 --- a/samples/performance/batch-decode.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import glob -from dbr import * - - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - reader = BarcodeReader.get_instance() - if reader == None : - raise BarcodeReaderError("Get instance failed") - # Replace by your own image path - image_folder = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../../images" - - for idx, img in enumerate(glob.glob(os.path.join(image_folder, "*.*"))): - print('Test', idx+1, img) - - # 3. Decode barcodes from an image file - text_results = reader.decode_file(img) - - # 4.Output the barcode text. - if text_results != None: - for text_result in text_results: - print("Barcode Format : ", text_result.barcode_format_string) - print("Barcode Text : ", text_result.barcode_text) - print("Localization Points : ", text_result.localization_result.localization_points) - print("Exception : ", text_result.exception) - print("-------------") - - print(40*'#') - reader.recycle_instance() - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/performance/read-rate-first-settings.py b/samples/performance/read-rate-first-settings.py deleted file mode 100644 index d9050f9..0000000 --- a/samples/performance/read-rate-first-settings.py +++ /dev/null @@ -1,114 +0,0 @@ -import os -from dbr import * - -def config_readrate_first(dbr:BarcodeReader): - - # Obtain current runtime settings of instance. - sts = dbr.get_runtime_settings() - - # Parameter 1. Set expected barcode formats - # Here the barcode scanner will try to find the maximal barcode formats. - sts.barcode_format_ids = EnumBarcodeFormat.BF_ALL - sts.barcode_format_ids_2 = EnumBarcodeFormat_2.BF2_DOTCODE | EnumBarcodeFormat_2.BF2_POSTALCODE - - # Parameter 2. Set expected barcode count. - # Here the barcode scanner will try to find 64 barcodes. - # If the result count does not reach the expected amount, the barcode scanner will try other algorithms in the setting list to find enough barcodes. - sts.expected_barcodes_count = 64 - - # Parameter 3. Set more binarization modes. - sts.binarization_modes = [EnumBinarizationMode.BM_LOCAL_BLOCK,EnumBinarizationMode.BM_THRESHOLD,0,0,0,0,0,0] - - # Parameter 4. Set more localization modes. - # LocalizationModes are all enabled as default. Barcode reader will automatically switch between the modes and try decoding continuously until timeout or the expected barcode count is reached. - # Please manually update the enabled modes list or change the expected barcode count to promote the barcode scanning speed. - # Read more about localization mode members: https://www.dynamsoft.com/barcode-reader/parameters/enum/parameter-mode-enums.html?ver=latest#localizationmode - sts.localization_modes = [EnumLocalizationMode.LM_CONNECTED_BLOCKS,EnumLocalizationMode.LM_SCAN_DIRECTLY,EnumLocalizationMode.LM_STATISTICS, - EnumLocalizationMode.LM_LINES,EnumLocalizationMode.LM_STATISTICS_MARKS,EnumLocalizationMode.LM_STATISTICS_POSTAL_CODE,0,0] - - # Parameter 5. Set more deblur modes. - # DeblurModes are all enabled as default. Barcode reader will automatically switch between the modes and try decoding continuously until timeout or the expected barcode count is reached. - # Please manually update the enabled modes list or change the expected barcode count to promote the barcode scanning speed. - # Read more about deblur mode members: https://www.dynamsoft.com/barcode-reader/parameters/enum/parameter-mode-enums.html#deblurmode - sts.deblur_modes = [EnumDeblurMode.DM_DIRECT_BINARIZATION,EnumDeblurMode.DM_THRESHOLD_BINARIZATION,EnumDeblurMode.DM_GRAY_EQUALIZATION, - EnumDeblurMode.DM_SMOOTHING,EnumDeblurMode.DM_MORPHING,EnumDeblurMode.DM_DEEP_ANALYSIS,EnumDeblurMode.DM_SHARPENING,0,0,0] - - # Parameter 6. Set scale up modes. - # It is a parameter to control the process for scaling up an image used for detecting barcodes with small module size - sts.scale_up_modes = [EnumScaleUpMode.SUM_AUTO,0,0,0,0,0,0,0] - - # Parameter 7. Set grayscale transformation modes. - # By default, the library can only locate the dark barcodes that stand on a light background. "GTM_INVERTED":The image will be transformed into inverted grayscale. - sts.grayscale_transformation_modes = [EnumGrayscaleTransformationMode.GTM_ORIGINAL,EnumGrayscaleTransformationMode.GTM_INVERTED,0,0,0,0,0,0] - - # Parameter 8. Enable dpm modes. - # It is a parameter to control how to read direct part mark (DPM) barcodes. - sts.dpm_code_reading_modes = [EnumDPMCodeReadingMode.DPMCRM_GENERAL,0,0,0,0,0,0,0] - - # Parameter 9. Increase timeout(ms). The barcode scanner will have more chances to find the expected barcode until it times out - sts.timeout = 30000 - - # Apply the new settings to the instance - dbr.update_runtime_settings(sts) - -def config_readrate_first_by_template(dbr:BarcodeReader): - # Compared with PublicRuntimeSettings, parameter templates have a richer ability to control parameter details. - # Please refer to the parameter explanation in "read-rate-first-template.json" to understand how to control read rate first. - template_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "read-rate-first-template.json" - error = dbr.init_runtime_settings_with_file(template_path, EnumConflictMode.CM_OVERWRITE) - if error[0] != EnumErrorCode.DBR_OK: - print("init_runtime_settings_with_file error: " + error[1]) - -def output_results(results:TextResult): - if results != None: - i = 0 - for res in results: - barcode_format = res.barcode_format_string - - print("Barcode " + str(i) + ":" + barcode_format + "," + res.barcode_text) - i = i+1 - else: - print("No data detected.") - - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - dbr = BarcodeReader.get_instance() - if dbr == None : - raise BarcodeReaderError("Get instance failed") - # Replace by your own image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../../images/AllSupportedBarcodeTypes.png" - - # Accuracy = The number of correctly decoded barcodes/the number of all decoded barcodes - # There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template. - print("Decode through PublicRuntimeSettings:") - - # 3.a config through PublicRuntimeSettings - config_readrate_first(dbr) - - # 4.a Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings. - results = dbr.decode_file(image_path,"") - - # 5.a Output the barcode format and barcode text. - output_results(results) - - print("\nDecode through parameters template:") - # 3.b config through parameters template - config_readrate_first_by_template(dbr) - - # 4.b Decode barcodes from an image file by template. - results = dbr.decode_file(image_path, "") - - # 5.b Output the barcode format and barcode text. - output_results(results) - dbr.recycle_instance() - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/performance/read-rate-first-template.json b/samples/performance/read-rate-first-template.json deleted file mode 100644 index 64be33a..0000000 --- a/samples/performance/read-rate-first-template.json +++ /dev/null @@ -1,134 +0,0 @@ -{ - "ImageParameter" : { - "BarcodeFormatIds" : [ "BF_ALL" ], - "BarcodeFormatIds_2" : [ "BF2_POSTALCODE", "BF2_DOTCODE" ], - "BinarizationModes" : [ - { - "BlockSizeX" : 0, - "BlockSizeY" : 0, - "EnableFillBinaryVacancy" : 1, - "ImagePreprocessingModesIndex" : -1, - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "BM_LOCAL_BLOCK", - "ThresholdCompensation" : 10 - }, - { - "BinarizationThreshold" : -1, - "ImagePreprocessingModesIndex" : -1, - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "BM_THRESHOLD" - }, - { - "BlockSizeX" : 0, - "BlockSizeY" : 0, - "EnableFillBinaryVacancy" : 0, - "ImagePreprocessingModesIndex" : -1, - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "BM_LOCAL_BLOCK", - "ThresholdCompensation" : 15 - } - ], - "DPMCodeReadingModes" : [ - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DPMCRM_GENERAL" - } - ], - "DeblurModes" : [ - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_DIRECT_BINARIZATION" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_THRESHOLD_BINARIZATION" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_GRAY_EQUALIZATION" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_SMOOTHING" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_MORPHING" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_DEEP_ANALYSIS" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "DM_SHARPENING" - } - ], - "ExpectedBarcodesCount" : 64, - "GrayscaleTransformationModes" : [ - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "GTM_ORIGINAL" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "GTM_INVERTED" - } - ], - "LocalizationModes" : [ - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "LM_CONNECTED_BLOCKS" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "LM_SCAN_DIRECTLY", - "ScanDirection" : 0, - "ScanStride" : 0 - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "LM_STATISTICS" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "LM_LINES" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "LM_STATISTICS_MARKS" - }, - { - "LibraryFileName" : "", - "LibraryParameters" : "", - "Mode" : "LM_STATISTICS_POSTAL_CODE" - } - ], - "Name" : "tpl_rfs", - "ScaleUpModes" : [ - { - "Mode" : "SUM_AUTO" - } - ], - "Timeout" : 30000 - }, - "Version" : "3.0" -} diff --git a/samples/performance/speed-first-settings.py b/samples/performance/speed-first-settings.py deleted file mode 100644 index 07b0d14..0000000 --- a/samples/performance/speed-first-settings.py +++ /dev/null @@ -1,123 +0,0 @@ -import os -from dbr import * - -def config_speed_first(dbr:BarcodeReader): - - # Obtain current runtime settings of instance. - sts = dbr.get_runtime_settings() - - # Parameter 1. Set expected barcode formats - # The simpler barcode format, the faster decoding speed. - # Here we use OneD barcode format to demonstrate. - sts.barcode_format_ids = EnumBarcodeFormat.BF_EAN_13 - - # Parameter 2. Set expected barcode count - # The less barcode count, the faster decoding speed. - sts.expected_barcodes_count = 1 - - # Parameter 3. Set the threshold for the image shrinking for localization. - # The smaller the threshold, the smaller the image shrinks. The default value is 2300. - sts.scale_down_threshold = 1200 - - # Parameter 4. Set the binarization mode for convert grayscale image to binary image. - # Mostly, the less binarization modes set, the faster decoding speed. - sts.binarization_modes = [EnumBinarizationMode.BM_LOCAL_BLOCK,0,0,0,0,0,0,0] - - # Parameter 5. Set localization mode. - # LM_SCAN_DIRECTLY: Localizes barcodes quickly. It is both for OneD and TweD barcodes. This mode is recommended in interactive scenario. - sts.localization_modes = [EnumLocalizationMode.LM_SCAN_DIRECTLY,0,0,0,0,0,0,0] - - # LM_ONED_FAST_SCAN: Localizing barcodes quickly. However, it is only for OneD barcodes. It is also recommended in interactive scenario. - # sts.localization_modes = [EnumLocalizationMode.LM_ONED_FAST_SCAN, 0,0,0,0,0,0,0] - - # Parameter 6. Reduce deblurModes setting - # DeblurModes will improve the readability and accuracy but decrease the reading speed. - # Please update your settings here if you want to enable different Deblurmodes. - sts.deblur_modes = [EnumDeblurMode.DM_BASED_ON_LOC_BIN,EnumDeblurMode.DM_THRESHOLD_BINARIZATION,0,0,0,0,0,0,0,0] - - # Parameter 7. Set timeout(ms) if the application is very time sensitive. - # If timeout, the decoding thread will exit at the next check point. - sts.timeout = 100 - - # Apply the new settings to the instance - dbr.update_runtime_settings(sts) - - # Other potentially accelerated arguments of various modes. - - # Argument 4.a Disable the EnableFillBinaryVacancy argument. - # Local block binarization process might cause vacant area in barcode. The barcode reader will fill the vacant black by default (default value 1). Set the value 0 to disable this process. - dbr.set_mode_argument("BinarizationModes", 0, "EnableFillBinaryVacancy", "0") - - # Argument 5.a Sets the scan direction when searching barcode. - # It is valid only when the type of LocalizationMode is LM_ONED_FAST_SCAN or LM_SCAN_DIRECTLY. - # 0: Both vertical and horizontal direction. - # 1: Vertical direction. - # 2: Horizontal direction. - # Read more about localization mode members: https://www.dynamsoft.com/barcode-reader/parameters/enum/parameter-mode-enums.html?ver=latest#localizationmode - dbr.set_mode_argument("LocalizationModes",0,"ScanDirection","0") - - -def config_speed_first_by_template(dbr:BarcodeReader): - # Compared with PublicRuntimeSettings, parameter templates have a richer ability to control parameter details. - # Please refer to the parameter explanation in "speed-first-template.json" to understand how to control speed first. - template_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "speed-first-template.json" - error = dbr.init_runtime_settings_with_file(template_path, EnumConflictMode.CM_OVERWRITE) - if error[0] != EnumErrorCode.DBR_OK: - print("init_runtime_settings_with_file error: " + error[1]) - -def output_results(results:TextResult): - if results != None: - i = 0 - for res in results: - barcode_format = res.barcode_format_string - - print("Barcode " + str(i) + ":" + barcode_format + "," + res.barcode_text) - i = i+1 - else: - print("No data detected.") - - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - dbr = BarcodeReader.get_instance() - if dbr == None: - raise BarcodeReaderError("Get instance failed") - # Replace by your own image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../../images/AllSupportedBarcodeTypes.png" - - # Accuracy = The number of correctly decoded barcodes/the number of all decoded barcodes - # There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template. - print("Decode through PublicRuntimeSettings:") - - # 3.a config through PublicRuntimeSettings - config_speed_first(dbr) - - # 4.a Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings. - results = dbr.decode_file(image_path,"") - - # 5.a Output the barcode format and barcode text. - output_results(results) - - print("\nDecode through parameters template:") - - # 3.b config through parameters template - config_speed_first_by_template(dbr) - - # 4.b Decode barcodes from an image file by template. - results = dbr.decode_file(image_path, "") - - # 5.b Output the barcode format and barcode text. - output_results(results) - - dbr.recycle_instance() - - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/performance/speed-first-template.json b/samples/performance/speed-first-template.json deleted file mode 100644 index 263847d..0000000 --- a/samples/performance/speed-first-template.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "ImageParameter" : { - "BarcodeFormatIds" : [ "BF_EAN_13" ], - "BarcodeFormatIds_2" : null, - "BinarizationModes" : [ - { - "Mode" : "BM_LOCAL_BLOCK", - "EnableFillBinaryVacancy" : 0 - } - ], - "DeblurModes" : [ - { - "Mode" : "DM_BASED_ON_LOC_BIN" - }, - { - "Mode" : "DM_THRESHOLD_BINARIZATION" - } - ], - "ExpectedBarcodesCount" : 1, - "LocalizationModes" : [ - { - "Mode" : "LM_SCAN_DIRECTLY", - "ScanDirection" : 0, - "ScanStride" : 0 - } - ], - "Name" : "tpl_sfs", - "ScaleDownThreshold" : 1200, - "Timeout" : 100 - }, - "Version" : "3.0" -} diff --git a/samples/use-case/read-dpm-barcode.py b/samples/use-case/read-dpm-barcode.py deleted file mode 100644 index d6e8f91..0000000 --- a/samples/use-case/read-dpm-barcode.py +++ /dev/null @@ -1,60 +0,0 @@ -import os -import sys -from dbr import * - -def output_results(results:TextResult): - if results != None: - i = 0 - for res in results: - barcode_format = res.barcode_format_string - - print("Barcode " + str(i) + ":" + barcode_format + "," + res.barcode_text) - i = i+1 - else: - print("No data detected.") - - -if __name__ == "__main__": - try: - # 1.Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # 2.Create an instance of Barcode Reader. - dbr = BarcodeReader.get_instance() - if dbr == None: - raise BarcodeReaderError("Get instance failed") - # 3.Config runtime settings for dmp - sts = dbr.get_runtime_settings() - - # 3.1. Set expected barcode formats. - # Generally, the most common dpm barcode is datamatrix or qrcode - sts.barcode_format_ids = EnumBarcodeFormat.BF_DATAMATRIX | EnumBarcodeFormat.BF_QR_CODE - - # 3.2. Set grayscale transformation modes. - # DPM barcodes may be dark and printed on the light background, or it may be light and printed on the dark background. - # By default, the library can only locate the dark barcodes that stand on a light background. "GTM_INVERTED":The image will be transformed into inverted grayscale. - sts.grayscale_transformation_modes = [EnumGrayscaleTransformationMode.GTM_ORIGINAL,EnumGrayscaleTransformationMode.GTM_INVERTED,0,0,0,0,0,0] - - # 3.3. Enable dpm modes. - # It is a parameter to control how to read direct part mark (DPM) barcodes. - sts.dpm_code_reading_modes = [EnumDPMCodeReadingMode.DPMCRM_GENERAL,0,0,0,0,0,0,0] - - dbr.update_runtime_settings(sts) - - # Replace with your own dpm barcode image path - image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../../images/dpm.jpg" - - # 3 Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings. - results = dbr.decode_file(image_path,"") - - # 4 Output the barcode format and barcode text. - output_results(results) - - dbr.recycle_instance() - - except BarcodeReaderError as bre: - print(bre) \ No newline at end of file diff --git a/samples/video-decoding-for-picamera.py b/samples/video-decoding-for-picamera.py deleted file mode 100644 index dcb4078..0000000 --- a/samples/video-decoding-for-picamera.py +++ /dev/null @@ -1,178 +0,0 @@ -import os -import sys -import time -import io -import numpy as np -from picamera import PiCamera -from picamera.array import PiRGBArray -from dbr import * -import cv2 - -# you can change the following variables' value to your own value. -json_file = r"Please input your own template path" - -def intermediate_results_callback_func(frame_id, i_results, user_data): - print(frame_id) - for result in i_results: - intermediate_result = IntermediateResult(result) - print('Intermediate Result data type : {0}'.format(intermediate_result.result_type)) - print('Intermediate Result data : {0}'.format(intermediate_result.results)) - print("-------------") -## Or you can inherit the abstract class IntermediateResultCallBack to implement the abstract method intermediate_results_callback_func. -# class SubIntermediateResultCallBack(IntermediateResultCallBack): -# @staticmethod -# def intermediate_results_callback_func(frame_id, i_results, user_data): -# print(frame_id) -# for result in i_results: -# intermediate_result = IntermediateResult(result) -# print('Intermediate Result data type : {0}'.format(intermediate_result.result_type)) -# print('Intermediate Result data : {0}'.format(intermediate_result.results)) -# print("-------------") - - -def text_results_callback_func(frame_id, t_results, user_data): - print(frame_id) - for result in t_results: - text_result = TextResult(result) - 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("Exception : ") - print(text_result.exception) - print("-------------") -## Or you can inherit the abstract class TextResultCallBack to implement the abstract method text_results_callback_func. -# class SubTextResultCallBack(TextResultCallBack): -# @staticmethod -# def text_results_callback_func(frame_id, t_results, user_data): -# print(frame_id) -# for result in t_results: -# text_result = TextResult(result) -# 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("Exception : ") -# print(text_result.exception) -# print("-------------") - - -def error_callback_func(frame_id, error_code, user_data): - print(frame_id) - error_msg = user_data.get_error_string(error_code) - print('Error : {0} ; {1}'.format(error_code, error_msg)) -## Or you can inherit the abstract class ErrorCallBack to implement the abstract method error_callback_func. -# class SubErrorCallBack(ErrorCallBack): -# @staticmethod -# def error_callback_func(frame_id, error_code, user_data): -# print(frame_id) -# error_msg = user_data.get_error_string(error_code) -# print('Error : {0} ; {1}'.format(error_code, error_msg)) - - -def get_time(): - localtime = time.localtime() - capturetime = time.strftime("%Y%m%d%H%M%S", localtime) - return capturetime - -def read_barcode(): - video_width = 0 - video_height = 0 - - # vc = cv2.VideoCapture(0) - camera = PiCamera() - camera.resolution = (1024, 1024) # Set image's width and height - - # SetPiCameraParameters(camera): - # camera.saturation = 80 # Video or Image saturation - # camera.brightness = 50 # Video or Image brightness - # camera.shutter_speed = 6000000 # The shutter speed - # camera.iso = 800 # ISO - # camera.sharpness = 0 # Image Sharpness - # camera.hflip = True # Whether to flip horizontally - # camera.vflip = True # Whether to flip vertically - # camera.rotation = 0 # Whether to rotate image - # camera.resolution = (280, 160) # Set image's width and height - - - video_width = camera.resolution[0] - video_height = camera.resolution[1] - print(camera.resolution) - - stride = 0 - stream = io.BytesIO() - camera.capture(stream, format='jpeg') - # create numpy by stream - data = np.frombuffer(stream.getvalue(), dtype=np.uint8) - # decode numpy by opencv - image = cv2.imdecode(data, 1) - stride = image.strides[0] - print(stride) - rawCapture = PiRGBArray(camera, size=(video_width, video_height)) - - windowName = "Barcode Reader" - - parameters = reader.init_frame_decoding_parameters() - # you can modify these following parameters. - parameters.max_queue_length = 30 - parameters.max_result_queue_length = 30 - parameters.width = video_width - parameters.height = video_height - parameters.stride = stride - parameters.image_pixel_format = EnumImagePixelFormat.IPF_RGB_888 - parameters.region_top = 0 - parameters.region_bottom = 100 - parameters.region_left = 0 - parameters.region_right = 100 - parameters.region_measured_by_percentage = 1 - parameters.threshold = 0.01 - parameters.fps = 0 - parameters.auto_filter = 1 - - reader.start_video_mode(parameters, text_results_callback_func) - # reader.start_video_mode(parameters, SubTextResultResultCallBack.text_results_callback_func) - ## You can use three callbacks at the same time. - # reader.start_video_mode(parameters, text_results_callback_func, "", intermediate_results_callback_func, error_callback_func, reader) - # reader.start_video_mode(parameters, SubTextResultResultCallBack.text_results_callback_func, "", SubIntermediateResultCallBack.intermediate_results_callback_func, SubErrorCallBack.error_callback_func, reader) - - for frame in camera.capture_continuous(rawCapture, format='bgr', use_video_port=True): - image = frame.array - - try: - ret = reader.append_video_frame(image) - except: - pass - - # 'ESC' for quit - key = cv2.waitKey(1) - # reset - rawCapture.truncate(0) - if key == 27: - break - - reader.stop_video_mode() - cv2.destroyWindow(windowName) - - -print("-------------------start------------------------") - -# Initialize license. -# The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. -# You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python -error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") -if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - -reader = BarcodeReader.get_instance() -if reader != None: - error = reader.init_runtime_settings_with_file(json_file) - if error[0] != EnumErrorCode.DBR_OK: - print(error[1]) - - read_barcode() - reader.recycle_instance() -print("-------------------over------------------------") \ No newline at end of file diff --git a/samples/video-decoding.py b/samples/video-decoding.py deleted file mode 100644 index fa10de0..0000000 --- a/samples/video-decoding.py +++ /dev/null @@ -1,120 +0,0 @@ -from dbr import * -import cv2 - -def text_results_callback_func(frame_id, t_results, user_data): - print(frame_id) - for result in t_results: - text_result = TextResult(result) - 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("Exception : ") - print(text_result.exception) - print("-------------") - -def intermediate_results_callback_func(frame_id, i_results, user_data): - print(frame_id) - for result in i_results: - intermediate_result = IntermediateResult(result) - print('Intermediate Result data type : {0}'.format(intermediate_result.result_type)) - print('Intermediate Result data : {0}'.format(intermediate_result.results)) - print("-------------") - -def error_callback_func(frame_id, error_code, user_data): - print(frame_id) - error_msg = user_data.get_error_string(error_code) - print('Error : {0} ; {1}'.format(error_code, error_msg)) - -def decode_video(): - video_width = 0 - video_height = 0 - - # a. Decode video from camera - vc = cv2.VideoCapture(0) - - # # b. Decode video file - # video_file = "Put your video file path here." - # vc = cv2.VideoCapture(video_file) - - video_width = int(vc.get(cv2.CAP_PROP_FRAME_WIDTH)) - video_height = int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT)) - vc.set(3, video_width) #set width - vc.set(4, video_height) #set height - - stride = 0 - if vc.isOpened(): - rval, frame = vc.read() - stride = frame.strides[0] - else: - return - - windowName = "Video Barcode Reader" - - reader = BarcodeReader.get_instance() - if reader == None: - raise BarcodeReaderError("Get instance failed") - parameters = reader.init_frame_decoding_parameters() - parameters.max_queue_length = 30 - parameters.max_result_queue_length = 30 - parameters.width = video_width - parameters.height = video_height - parameters.stride = stride - parameters.image_pixel_format = EnumImagePixelFormat.IPF_RGB_888 - parameters.region_top = 0 - parameters.region_bottom = 100 - parameters.region_left = 0 - parameters.region_right = 100 - parameters.region_measured_by_percentage = 1 - parameters.threshold = 0.01 - parameters.fps = 0 - parameters.auto_filter = 1 - - # start video decoding. The callback function will receive the recognized barcodes. - reader.start_video_mode(parameters, text_results_callback_func) - - # # start video decoding. Pass three callbacks at the same time. - # reader.start_video_mode(parameters, text_results_callback_func, "", intermediate_results_callback_func, error_callback_func, reader) - - while True: - cv2.imshow(windowName, frame) - rval, frame = vc.read() - if rval == False: - break - - try: - # append frame to video buffer cyclically - ret = reader.append_video_frame(frame) - except: - pass - - # 'ESC' for quit - key = cv2.waitKey(1) - if key == 27: - break - - reader.stop_video_mode() - cv2.destroyWindow(windowName) - reader.recycle_instance() - -if __name__ == "__main__": - - print("-------------------start------------------------") - - try: - # Initialize license. - # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. - # You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?architecture=dcv&product=dbr&utm_source=samples&package=python - error = BarcodeReader.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9") - if error[0] != EnumErrorCode.DBR_OK: - print("License error: "+ error[1]) - - # Decode video from file or camera - decode_video() - - except BarcodeReaderError as bre: - print(bre) - - print("-------------------over------------------------") \ No newline at end of file