Skip to content

Commit

Permalink
refactor: adding mutex to variable access
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioReyesSan committed Jan 17, 2025
1 parent 1cd430b commit 9a2f940
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def __init__(self, **kwargs):
self.lost_frames = 0

def restart_lost_frames_counter(self):
self.lost_frames = self.max_lost_frames.value
with self.lock:
self.lost_frames = self.max_lost_frames.value

def detect(self, img: np.array, stamp: float):
"""Slot to detect boards from an image. Results are sent through the detection_results signals."""
Expand All @@ -62,8 +63,10 @@ def detect(self, img: np.array, stamp: float):

resized_detection = self.resized_detection.value
resized_max_resolution = self.resized_max_resolution.value
local_padding = self.padding.value
max_lost_frames = self.max_lost_frames.value

def get_roi(corners, frame_shape, padding=self.padding.value):
def get_roi(corners, frame_shape, padding=local_padding):
# Region to keep track of the chessboard in the next frame
x_min, y_min = np.min(corners, axis=0).ravel().astype(int) - padding
x_max, y_max = np.max(corners, axis=0).ravel().astype(int) + padding
Expand All @@ -74,7 +77,7 @@ def get_roi(corners, frame_shape, padding=self.padding.value):
h, w = img.shape[0:2]
grayscale = to_grayscale(img)
if not resized_detection or max(h, w) <= resized_max_resolution:
if self.roi is None or self.lost_frames >= self.max_lost_frames.value:
if self.roi is None or self.lost_frames >= max_lost_frames:
(detected, corners) = cv2.findChessboardCorners(
grayscale, (cols, rows), flags=flags
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def make_mode_group(self):

self.rectify_label = QLabel("Rectify option:")
self.rectify_type_combobox = QComboBox()
self.rectify_type_combobox.addItem("Opencv", 0)
self.rectify_type_combobox.addItem("OpenCV", 0)
self.rectify_type_combobox.addItem("Fixed aspect ratio", 1)
self.rectify_type_combobox.setEnabled(False)

Expand Down

0 comments on commit 9a2f940

Please sign in to comment.