Spaces:
Build error
Build error
Commit ·
a31fde5
1
Parent(s): f47c521
Add code to the mina program
Browse files- src/deep_barcode_reader/main.py +68 -35
src/deep_barcode_reader/main.py
CHANGED
|
@@ -1,35 +1,68 @@
|
|
| 1 |
-
"""Run the main code for Deep-Barcode-Reader"""
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
from deep_barcode_reader
|
| 10 |
-
from deep_barcode_reader.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
@click.
|
| 17 |
-
@click.
|
| 18 |
-
@click.option(
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
"
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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__
|
| 10 |
+
from deep_barcode_reader.logging import config_logger
|
| 11 |
+
from deep_barcode_reader.barcode import Wrapper
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@click.command()
|
| 17 |
+
@click.version_option(version=__version__)
|
| 18 |
+
@click.option(
|
| 19 |
+
"-v",
|
| 20 |
+
"--verbose",
|
| 21 |
+
count=True,
|
| 22 |
+
help="Shorthand for info/debug/warning/error loglevel (-v/-vv/-vvv/-vvvv)",
|
| 23 |
+
)
|
| 24 |
+
@click.option(
|
| 25 |
+
"-s",
|
| 26 |
+
"--result_path",
|
| 27 |
+
type=str,
|
| 28 |
+
default="output/test.png",
|
| 29 |
+
help="Path to save the result file.",
|
| 30 |
+
)
|
| 31 |
+
@click.option(
|
| 32 |
+
"-d",
|
| 33 |
+
"--data_path",
|
| 34 |
+
required=True,
|
| 35 |
+
type=click.Path(exists=True),
|
| 36 |
+
help="Path to data file.",
|
| 37 |
+
)
|
| 38 |
+
@click.option(
|
| 39 |
+
"-m",
|
| 40 |
+
"--method",
|
| 41 |
+
type=click.Choice(["opencv", "zbar", "qrreader"], case_sensitive=False),
|
| 42 |
+
default="opencv",
|
| 43 |
+
help="Path to data file.",
|
| 44 |
+
)
|
| 45 |
+
@click.option(
|
| 46 |
+
"--model_size",
|
| 47 |
+
type=click.Choice(["n", "n", "m", "l"], case_sensitive=False),
|
| 48 |
+
default="m",
|
| 49 |
+
help="Model size for the barcode reader.",
|
| 50 |
+
)
|
| 51 |
+
def deep_barcode_reader_cli(
|
| 52 |
+
verbose: int, result_path: str, data_path: Path, method: str, model_size: str
|
| 53 |
+
) -> None:
|
| 54 |
+
"""It can read different types of barcodes"""
|
| 55 |
+
if verbose == 1:
|
| 56 |
+
log_level = 10
|
| 57 |
+
elif verbose == 2:
|
| 58 |
+
log_level = 20
|
| 59 |
+
elif verbose == 3:
|
| 60 |
+
log_level = 30
|
| 61 |
+
else:
|
| 62 |
+
log_level = 40
|
| 63 |
+
config_logger(log_level)
|
| 64 |
+
|
| 65 |
+
reader = Wrapper(model_size=model_size, method=method)
|
| 66 |
+
_ = asyncio.get_event_loop().run_until_complete(
|
| 67 |
+
reader.method_selection(result_path=result_path, data_path=str(data_path))
|
| 68 |
+
)
|