Spaces:
Build error
Build error
Commit ·
1b8dd75
1
Parent(s): 71b7c54
Update the main code to have the detection results in data as well as img type
Browse files
src/deep_barcode_reader/__init__.py
CHANGED
|
@@ -1,3 +1,14 @@
|
|
| 1 |
-
""" It can read different types of barcodes """
|
| 2 |
-
|
| 3 |
-
__version__ = "0.2.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" It can read different types of barcodes """
|
| 2 |
+
|
| 3 |
+
__version__ = "0.2.0"
|
| 4 |
+
|
| 5 |
+
from .barcode import Wrapper, QRreader, BarcodeOpencv, BarcodeQRZbar
|
| 6 |
+
from .base import ReaderResults
|
| 7 |
+
|
| 8 |
+
__all__ = [
|
| 9 |
+
"Wrapper",
|
| 10 |
+
"QRreader",
|
| 11 |
+
"BarcodeOpencv",
|
| 12 |
+
"BarcodeQRZbar",
|
| 13 |
+
"ReaderResults",
|
| 14 |
+
]
|
src/deep_barcode_reader/barcode.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
# pylint: disable=E1101
|
| 4 |
import logging
|
| 5 |
-
from typing import Any
|
| 6 |
from dataclasses import dataclass, field
|
| 7 |
from pathlib import Path
|
| 8 |
|
|
@@ -145,7 +145,7 @@ class Wrapper:
|
|
| 145 |
method: str = field(default="opencv")
|
| 146 |
model_size: str = field(default="l")
|
| 147 |
|
| 148 |
-
async def method_selection(self,
|
| 149 |
"""Wrap the method selection for barcode reader"""
|
| 150 |
if self.method == "opencv":
|
| 151 |
barcode: Any = BarcodeOpencv()
|
|
@@ -155,5 +155,6 @@ class Wrapper:
|
|
| 155 |
barcode = QRreader(model_size=self.model_size)
|
| 156 |
else:
|
| 157 |
barcode = BarcodeOpencv()
|
| 158 |
-
detections = await barcode.detect_decode(
|
| 159 |
-
|
|
|
|
|
|
| 2 |
|
| 3 |
# pylint: disable=E1101
|
| 4 |
import logging
|
| 5 |
+
from typing import Any, Tuple
|
| 6 |
from dataclasses import dataclass, field
|
| 7 |
from pathlib import Path
|
| 8 |
|
|
|
|
| 145 |
method: str = field(default="opencv")
|
| 146 |
model_size: str = field(default="l")
|
| 147 |
|
| 148 |
+
async def method_selection(self, image: Any, result_path: str) -> Tuple[Any, Any]:
|
| 149 |
"""Wrap the method selection for barcode reader"""
|
| 150 |
if self.method == "opencv":
|
| 151 |
barcode: Any = BarcodeOpencv()
|
|
|
|
| 155 |
barcode = QRreader(model_size=self.model_size)
|
| 156 |
else:
|
| 157 |
barcode = BarcodeOpencv()
|
| 158 |
+
detections = await barcode.detect_decode(image)
|
| 159 |
+
result_image = await detections.visualize_results_async(result_path)
|
| 160 |
+
return detections, result_image
|
src/deep_barcode_reader/logging.py
CHANGED
|
@@ -1,30 +1,30 @@
|
|
| 1 |
-
"""Logger initialization"""
|
| 2 |
-
|
| 3 |
-
import logging
|
| 4 |
-
import logging.config
|
| 5 |
-
from typing import Any
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def config_logger(loglevel: int) -> Any:
|
| 9 |
-
"""Initialize a custom logger"""
|
| 10 |
-
default_logging_config = {
|
| 11 |
-
"version": 1,
|
| 12 |
-
"disable_existing_loggers": False,
|
| 13 |
-
"formatters": {
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
},
|
| 18 |
-
},
|
| 19 |
-
"handlers": {
|
| 20 |
-
"console": {
|
| 21 |
-
"class": "logging.StreamHandler",
|
| 22 |
-
"formatter": "standard",
|
| 23 |
-
},
|
| 24 |
-
},
|
| 25 |
-
"root": {
|
| 26 |
-
"handlers": ["console"],
|
| 27 |
-
"level": loglevel,
|
| 28 |
-
},
|
| 29 |
-
}
|
| 30 |
-
logging.config.dictConfig(default_logging_config)
|
|
|
|
| 1 |
+
"""Logger initialization"""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import logging.config
|
| 5 |
+
from typing import Any
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def config_logger(loglevel: int) -> Any:
|
| 9 |
+
"""Initialize a custom logger"""
|
| 10 |
+
default_logging_config = {
|
| 11 |
+
"version": 1,
|
| 12 |
+
"disable_existing_loggers": False,
|
| 13 |
+
"formatters": {
|
| 14 |
+
"standard": {
|
| 15 |
+
"format": "%(asctime)s - [%(levelname)s] [%(name)s.%(funcName)s:%(lineno)d (%(process)d)] | %(message)s",
|
| 16 |
+
"datefmt": "%Y-%m-%d %H:%M:%S",
|
| 17 |
+
},
|
| 18 |
+
},
|
| 19 |
+
"handlers": {
|
| 20 |
+
"console": {
|
| 21 |
+
"class": "logging.StreamHandler",
|
| 22 |
+
"formatter": "standard",
|
| 23 |
+
},
|
| 24 |
+
},
|
| 25 |
+
"root": {
|
| 26 |
+
"handlers": ["console"],
|
| 27 |
+
"level": loglevel,
|
| 28 |
+
},
|
| 29 |
+
}
|
| 30 |
+
logging.config.dictConfig(default_logging_config)
|
src/deep_barcode_reader/main.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
"""Run the main code for Deep-Barcode-Reader"""
|
| 2 |
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
import logging
|
| 5 |
import asyncio
|
| 6 |
import click
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
from deep_barcode_reader import __version__
|
|
@@ -64,5 +66,7 @@ def deep_barcode_reader_cli(
|
|
| 64 |
|
| 65 |
reader = Wrapper(model_size=model_size, method=method)
|
| 66 |
_ = asyncio.get_event_loop().run_until_complete(
|
| 67 |
-
reader.method_selection(
|
|
|
|
|
|
|
| 68 |
)
|
|
|
|
| 1 |
"""Run the main code for Deep-Barcode-Reader"""
|
| 2 |
|
| 3 |
+
# pylint: disable=E1101
|
| 4 |
from pathlib import Path
|
| 5 |
import logging
|
| 6 |
import asyncio
|
| 7 |
import click
|
| 8 |
+
import cv2
|
| 9 |
|
| 10 |
|
| 11 |
from deep_barcode_reader import __version__
|
|
|
|
| 66 |
|
| 67 |
reader = Wrapper(model_size=model_size, method=method)
|
| 68 |
_ = asyncio.get_event_loop().run_until_complete(
|
| 69 |
+
reader.method_selection(
|
| 70 |
+
image=cv2.imread(str(data_path)), result_path=result_path
|
| 71 |
+
)
|
| 72 |
)
|