Skip to content

Commit 1904369

Browse files
committed
add logging
1 parent 9bf1906 commit 1904369

File tree

14 files changed

+60
-21
lines changed

14 files changed

+60
-21
lines changed

dls_barcode/config/camera_config_control.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import cv2
23
from PyQt5.QtCore import Qt
34
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QHBoxLayout, QMessageBox, QLineEdit, QPushButton, QComboBox
@@ -15,6 +16,7 @@ def __init__(self, camera_config):
1516
ConfigControl.__init__(self, camera_config)
1617
self._camera_config = camera_config
1718
self._init_ui()
19+
self.log = logging.getLogger(".".join([__name__]))
1820

1921
def _init_ui(self):
2022
# Set Camera Number
@@ -60,9 +62,10 @@ def save_to_config(self):
6062
def _test_camera(self):
6163
self.save_to_config()
6264
try:
63-
self._test_camera_settings()
64-
self._display_camera_preview()
65+
self._test_camera_settings()
66+
self._display_camera_preview()
6567
except ValueError:
68+
self.log.error("Camera Error - Cannot find specified camera")
6669
QMessageBox.critical(self, "Camera Error", "Cannot find specified camera")
6770

6871

@@ -79,6 +82,7 @@ def _test_camera_settings(self):
7982
stream.release_resources()
8083
if not read_ok:
8184
# Capture the next frame from the camera
85+
self.log.error(ValueError("Read not OK"))
8286
raise ValueError
8387

8488
def _display_camera_preview(self):

dls_barcode/datamatrix/datamatrix.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from dls_util.image.image import Image
23
from .locate import Locator
34
from pylibdmtx.pylibdmtx import decode
@@ -42,6 +43,7 @@ def __init__(self, finder_pattern):
4243
self._read_ok = False
4344
self._damaged_symbol = False
4445
self._is_read_performed = False
46+
self.log = logging.getLogger(".".join([__name__]))
4547

4648
def set_matrix_sizes(self, matrix_sizes):
4749
self._matrix_sizes = [int(v) for v in matrix_sizes]
@@ -64,20 +66,23 @@ def is_read(self):
6466
def is_valid(self):
6567
""" True if the data matrix was read successfully. """
6668
if not self._is_read_performed:
69+
self.log.debug("data matrix not read successfully")
6770
raise BarcodeReadNotPerformedException()
6871

6972
return self._read_ok
7073

7174
def is_unreadable(self):
7275
""" True if the data matrix could not be decoded (because of damage to the symbol). """
7376
if not self._is_read_performed:
77+
self.log.debug("data matrix not read successfully")
7478
raise BarcodeReadNotPerformedException()
7579

7680
return self._damaged_symbol
7781

7882
def data(self):
7983
""" String representation of the barcode data. """
8084
if not self._is_read_performed:
85+
self.log.debug("data matrix not read successfully")
8186
raise BarcodeReadNotPerformedException()
8287

8388
if self._read_ok:
@@ -103,8 +108,7 @@ def _read(self, gray_image):
103108
"""
104109
try:
105110

106-
cv2.imshow("Erode", gray_image)
107-
cv2.waitKey(0)
111+
108112
result = decode(gray_image, max_count = 1)
109113
if len(result) > 0:
110114
d = result[0].data
@@ -115,6 +119,8 @@ def _read(self, gray_image):
115119
self._error_message = ""
116120
else:
117121
self._read_ok = False
122+
#cv2.imshow("Erode", gray_image)
123+
#cv2.waitKey(0)
118124
except(Exception) as ex:
119125
self._read_ok = False
120126
self._error_message = str(ex)

dls_barcode/datamatrix/locate/locate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def locate_deep(self, img, expected_radius=None, filter_overlap=False):
7272
finder_patterns = self._filter_overlapping_patterns(finder_patterns)
7373

7474
# If the fps are asymmetrical, correct the side lengths
75-
side = expected_radius * (2 / math.sqrt(2))
76-
finder_patterns = [fp.correct_lengths(side) for fp in finder_patterns]
75+
if expected_radius is not None:
76+
side = expected_radius * (2 / math.sqrt(2))
77+
finder_patterns = [fp.correct_lengths(side) for fp in finder_patterns]
7778

7879
return finder_patterns
7980

dls_barcode/datamatrix/locate/locate_contour.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ def locate_datamatrices(self, gray_image, blocksize, C, close_size):
2424
"""
2525
# Perform adaptive threshold, reducing to a binary image
2626
threshold_image = self._do_threshold(gray_image, blocksize, C)
27+
cv2.imshow("threshold", threshold_image.img)
28+
cv2.waitKey(0)
2729

2830
# Perform a morphological close, removing noise and closing some gaps
2931
morphed_image = self._do_close_morph(threshold_image, close_size)
32+
cv2.imshow("morph", threshold_image.img)
33+
cv2.waitKey(0)
3034

3135
# Find a bunch of contours in the image.
3236
contours = self._get_contours(morphed_image)

dls_barcode/frame_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def __init__(self, side_camera_stream, side_frame) -> None:
1818
def run(self):
1919
side_result = self._side_camera_stream.process_frame(self._side_frame)
2020
if side_result.error() is not None:
21-
self._log.debug(side_result.error().content())
21+
# self._log.debug(side_result.error().content())
2222
self.side_scan_error_signal.emit(side_result.error())
2323
if side_result.has_valid_barcodes():
24-
self._log.debug("side has valid barcodes")
24+
# self._log.debug("side has valid barcodes")
2525
self.side_result_signal.emit(side_result)
2626

2727
self.finished.emit()
@@ -39,7 +39,7 @@ def __init__(self, top_camera_stream, top_frame) -> None:
3939

4040
def run(self):
4141
top_result = self._top_camera_stream.process_frame(self._top_frame)
42-
42+
4343
if top_result.success():
4444
self.top_result_signal.emit(top_result)
4545
if top_result.is_full_valid():

dls_barcode/geometry/geometry.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from .exception import GeometryException
23
from .blank import BlankGeometry
34
from .unipuck import Unipuck
@@ -46,8 +47,12 @@ def get_num_slots(geo_name):
4647

4748
@staticmethod
4849
def _raise_not_implemented(geo_name):
50+
log = logging.getLogger(".".join([__name__]))
51+
log.debug(Geometry._MSG_NOT_IMPLEMENTED.format(geo_name))
4952
raise GeometryException(Geometry._MSG_NOT_IMPLEMENTED.format(geo_name))
5053

5154
@staticmethod
5255
def _raise_unknown(geo_name):
56+
log = logging.getLogger(".".join([__name__]))
57+
log.debug(Geometry._MSG_UNKNOWN.format(geo_name))
5358
raise GeometryException(Geometry._MSG_UNKNOWN.format(geo_name))

dls_barcode/geometry/unipuck_calculator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import division
2+
import logging
23

34
import time
45

@@ -32,13 +33,16 @@ def __init__(self, slot_centers):
3233
"""
3334
self._num_slots = UnipuckTemplate.NUM_SLOTS
3435
self._slot_centers = slot_centers
36+
self.log = logging.getLogger(".".join([__name__]))
3537

3638
def perform_alignment(self):
3739
num_points = len(self._slot_centers)
3840

3941
if num_points > self._num_slots:
42+
self.log.debug("Too many slots detected to perform Unipuck alignment")
4043
raise GeometryAlignmentError("Too many slots detected to perform Unipuck alignment")
4144
elif num_points < MIN_POINTS_FOR_ALIGNMENT:
45+
self.log.debug("Not enough slots detected to perform Unipuck alignment")
4246
raise GeometryAlignmentError("Not enough slots detected to perform Unipuck alignment")
4347

4448
puck = self._calculate_puck_alignment()
@@ -58,6 +62,7 @@ def _calculate_puck_alignment(self):
5862
return puck
5963

6064
except Exception:
65+
self.log.error(GeometryAlignmentError("Unipuck alignment failed"))
6166
raise GeometryAlignmentError("Unipuck alignment failed")
6267

6368
@staticmethod
@@ -125,6 +130,8 @@ def _determine_puck_orientation(puck, pin_centers):
125130

126131
average_error = best_sse / (puck.radius() ** 2) / len(pin_centers)
127132
if average_error > 0.003:
133+
log = logging.getLogger(".".join([__name__]))
134+
log.debug("Unable to determine Unipuck orientation")
128135
raise GeometryAlignmentError("Unable to determine Unipuck orientation")
129136

130137
return best_angle
@@ -179,6 +186,8 @@ def _partition(numbers):
179186
than the average of the first.
180187
"""
181188
if len(numbers) < 3:
189+
log = logging.getLogger(".".join([__name__]))
190+
log.debug("Not enought elements to run partition")
182191
raise Exception("Not enought elements to run partition")
183192

184193
numbers.sort()
@@ -187,6 +196,8 @@ def _partition(numbers):
187196

188197
while s < len(numbers):
189198
if not numbers[:s + 1] or not numbers[-s - 1:]:
199+
log = logging.getLogger(".".join([__name__]))
200+
log.debug("Empty slice")
190201
raise Exception("Empty slice")
191202

192203
gp1_average = np.mean(numbers[:s + 1])

dls_barcode/gui/main_window.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,13 @@ def _load_store_records(self):
207207
self._record_table._load_store_records()
208208

209209
def addRecordFrame(self, top_result, side_result):
210-
holder_barcode = side_result.get_first_barcode().data()
211-
plate = top_result.plate()
212-
holder_image = side_result.get_frame_image()
213-
pins_image = top_result.get_frame_image()
214-
self._record_table.add_record_frame(holder_barcode, plate, holder_image, pins_image)
215-
self._plate_beep(plate, self._config.get_scan_beep())
210+
if top_result.error() is None:
211+
holder_barcode = side_result.get_first_barcode().data()
212+
plate = top_result.plate()
213+
holder_image = side_result.get_frame_image()
214+
pins_image = top_result.get_frame_image()
215+
self._record_table.add_record_frame(holder_barcode, plate, holder_image, pins_image)
216+
self._plate_beep(plate, self._config.get_scan_beep())
216217

217218
def startCountdown(self, duration):
218219
self._log.debug("Countdown started")

dls_barcode/plate/geometry_adjuster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def adjust(self, plate, barcodes):
2929
# will cause this frame to be skipped).
3030
valid_barcodes = [bc for bc in barcodes if bc.is_read() and bc.is_valid()]
3131
if len(valid_barcodes) < 2:
32+
log.debug("Geometry adjustment failed.")
3233
raise GeometryAdjustmentError("Geometry adjustment failed.")
3334

3435
log.debug("ALIGNMENT ADJUSTMENT") # DEBUG

dls_barcode/scan/open/open_scanner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from dls_barcode.camera.scanner_message import ScanErrorMessage
23
from dls_barcode.datamatrix import DataMatrix
34

@@ -76,8 +77,9 @@ def _locate_all_barcodes_in_image(self):
7677
barcodes = DataMatrix.locate_all_barcodes_in_image_deep(self._frame_img, self.barcode_sizes)
7778
else:
7879
barcodes = DataMatrix.locate_all_barcodes_in_image(self._frame_img, self.barcode_sizes)
79-
# TODO: log the error
8080
if len(barcodes) == 0:
81+
# log = logging.getLogger(".".join([__name__]))
82+
# log.error(NoBarcodesDetectedError())
8183
raise NoBarcodesDetectedError()
8284
return barcodes
8385

0 commit comments

Comments
 (0)