Skip to content

Commit 8c7685f

Browse files
committed
open scan system test which fails + more logs
1 parent bd4c588 commit 8c7685f

File tree

12 files changed

+613
-414
lines changed

12 files changed

+613
-414
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"request": "launch",
88
"program": "${workspaceFolder}/main.py",
99
"console": "integratedTerminal"
10-
}
10+
}
1111
]
1212
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"import sys; sys.path.append('C:\\Users\\rqq82173\\Documents\\PuckBarcodeReader')"
55
],
66
"python.testing.pytestArgs": [
7-
"./tests/",
7+
"tests"
88
],
99
"python.testing.pytestEnabled": true,
1010
"python.testing.unittestEnabled": false,

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pygelf = "*"
2121
opencv-python = "*"
2222
pyperclip = "*"
2323
scipy = "*"
24-
pyqt5 = "*"
2524
numpy = "*"
2625
pytest-isort = "*"
26+
pyqt5 = "*"
2727

2828
[scripts]
2929
tests_dls_util = "python -m pytest --cov dls_util tests/unit_tests"

Pipfile.lock

Lines changed: 514 additions & 406 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dls_barcode/camera/stream_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from dls_barcode.gui.message_factory import MessageFactory
23
from dls_barcode.scan.scan_result import ScanResult
34
from dls_barcode.camera.camera_position import CameraPosition
@@ -11,7 +12,8 @@ def __init__(self, camera_config, cam_position):
1112
self.camera_config = camera_config
1213
self.camera_position = cam_position
1314
self.stream = None
14-
self._scanner = None
15+
self._scanner = None
16+
self._log = logging.getLogger(".".join([__name__]))
1517

1618
def initialise_stream(self, ):
1719
self.stream = CaptureManager(self.camera_config)
@@ -32,6 +34,7 @@ def create_scanner(self,config):
3234

3335
if plate_type == "None":
3436
self._scanner = OpenScanner(barcode_sizes)
37+
self._log.debug("Open Geometry")
3538
else:
3639
self._scanner = GeometryScanner(plate_type, barcode_sizes)
3740

dls_barcode/datamatrix/datamatrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def locate_all_barcodes_in_image(grayscale_img, matrix_sizes=[DEFAULT_SIZE]):
154154
return unread_barcodes
155155

156156
@staticmethod
157-
def locate_all_barcodes_in_image_deep(grayscale_img, matrix_sizes=[DEFAULT_SIZE]):
157+
def locate_all_barcodes_in_image_deep(grayscale_img, matrix_sizes=[DEFAULT_SIDE_SIZES]):
158158
""" Searches the image for all datamatrix finder patterns
159159
"""
160160
# TODO: deep scan is more likely to find some false finder patterns. Filter these out

dls_barcode/frame_processor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from PyQt5.QtCore import QObject, pyqtSignal
23
from dls_barcode.camera.scanner_message import ScanErrorMessage
34
from dls_barcode.scan.scan_result import ScanResult
@@ -10,14 +11,17 @@ class SideProcessor(QObject):
1011

1112
def __init__(self, side_camera_stream, side_frame) -> None:
1213
super().__init__()
14+
self._log = logging.getLogger(".".join([__name__]))
1315
self._side_camera_stream = side_camera_stream
1416
self._side_frame = side_frame
1517

1618
def run(self):
1719
side_result = self._side_camera_stream.process_frame(self._side_frame)
1820
if side_result.error() is not None:
21+
self._log.debug(side_result.error().content())
1922
self.side_scan_error_signal.emit(side_result.error())
2023
if side_result.has_valid_barcodes():
24+
self._log.debug("side has valid barcodes")
2125
self.side_result_signal.emit(side_result)
2226

2327
self.finished.emit()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os, shutil
2+
3+
from mock import MagicMock
4+
5+
from dls_barcode.config.barcode_config import BarcodeConfig
6+
from dls_barcode.data_store import Store
7+
from dls_barcode.data_store.store_writer import StoreWriter
8+
from dls_barcode.scan import OpenScanner
9+
from dls_util.image import Image
10+
from dls_util.file import FileManager
11+
from dls_util.cv.frame import Frame
12+
from pylibdmtx.pylibdmtx import decode
13+
import cv2
14+
15+
16+
class TestOpensScan():
17+
18+
# SHOULD BE OPEN CV 2.4.10
19+
20+
# Directory storing all of the test images
21+
TEST_IMG_DIR = 'tests/test-resources/new_side'
22+
CONFIG_FILE = os.path.join(TEST_IMG_DIR, "system_test_config.ini")
23+
FILE_MANAGER = FileManager()
24+
OPTIONS = BarcodeConfig(CONFIG_FILE, FILE_MANAGER)
25+
26+
# Clear store before creating a new one
27+
store_dir = OPTIONS.store_directory
28+
if os.path.isdir(store_dir.value()):
29+
shutil.rmtree(store_dir.value())
30+
31+
comms_manger = StoreWriter(OPTIONS.get_store_directory(), "store")
32+
STORE = Store(comms_manger, MagicMock())
33+
34+
35+
def test_generator(self):
36+
TEST_CASES = self.generate_test_cases()
37+
for params in TEST_CASES:
38+
self.run_scans(params[0], params[1])
39+
40+
41+
def run_scans(self, img_file, expected_code):
42+
filepath = os.path.join(self.TEST_IMG_DIR, img_file)
43+
cv_image = Image.from_file(filepath)
44+
f = Frame(None)
45+
f._image = cv_image
46+
result = OpenScanner([12,14]).scan_next_frame(f, is_single_image=True)
47+
barcode = result._barcodes[0].data()
48+
assert barcode == expected_code
49+
50+
51+
52+
def generate_test_cases(self):
53+
# Barcode data that is expected to appear in each image of the pucks
54+
side_code_old ='DF-039'
55+
56+
side_code_new ='ASAP02'
57+
58+
# List of files for Puck type 1
59+
side_testcases = [('old_side.png', side_code_old),('new_side.jpg', side_code_new)]
60+
61+
# Create a list of test cases
62+
test_cases = []
63+
test_cases.extend(side_testcases)
64+
return test_cases
65+

tests/system_tests/test_unipuck_scan.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from dls_barcode.scan import GeometryScanner
99
from dls_util.image import Image
1010
from dls_util.file import FileManager
11+
from dls_util.cv.frame import Frame
1112

1213
# SHOULD BE OPEN CV 2.4.10
1314

@@ -29,14 +30,15 @@
2930
def test_generator():
3031
TEST_CASES = generate_test_cases()
3132
for params in TEST_CASES:
32-
yield run_scans, params[0], params[1]
33+
run_scans(params[0], params[1])
3334

3435

3536
def run_scans(img_file, expected_codes):
3637
filepath = os.path.join(TEST_IMG_DIR, img_file)
3738
cv_image = Image.from_file(filepath)
38-
gray_image = cv_image.to_grayscale()
39-
results = GeometryScanner("Unipuck", [14]).scan_next_frame(gray_image, is_single_image=True)
39+
f = Frame(None)
40+
f._image = cv_image
41+
results = GeometryScanner("Unipuck", [14]).scan_next_frame(f, is_single_image=True)
4042
plate = results.plate()
4143
store_scan(img_file, plate, cv_image)
4244

122 KB
Loading

0 commit comments

Comments
 (0)