afshin-dini commited on
Commit
a31fde5
·
1 Parent(s): f47c521

Add code to the mina program

Browse files
Files changed (1) hide show
  1. 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
- from pathlib import Path
3
- import logging
4
- import asyncio
5
- import click
6
- import cv2
7
-
8
- from deep_barcode_reader import __version__
9
- from deep_barcode_reader.logging import config_logger
10
- from deep_barcode_reader.barcode import BarcodeOpencv, BarcodeQRZbar
11
-
12
- logger = logging.getLogger(__name__)
13
-
14
-
15
- @click.command()
16
- @click.version_option(version=__version__)
17
- @click.option("-v", "--verbose", count=True, help="Shorthand for info/debug/warning/error loglevel (-v/-vv/-vvv/-vvvv)")
18
- @click.option("-s", "--result_path", type=click.Path(), default=Path("output"), help="Path to save the result file.")
19
- @click.option("-d", "--data_path", required=True, type=click.Path(exists=True), help="Path to data file.")
20
- @click.option("--model_size", type=click.Choice(["n", "s", "m", "l"], case_sensitive=False), help="Path to data file.")
21
- def deep_barcode_reader_cli(verbose: int, result_path: Path, data_path: Path, model_size: str) -> None:
22
- """It can read different types of barcodes """
23
- if verbose == 1:
24
- log_level = 10
25
- elif verbose == 2:
26
- log_level = 20
27
- elif verbose == 3:
28
- log_level = 30
29
- else:
30
- log_level = 40
31
- config_logger(log_level)
32
-
33
- click.echo("Run the main code.")
34
- barcode = BarcodeQRZbar()
35
- _ = asyncio.get_event_loop().run_until_complete(barcode.test_run())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ )