Skip to content

Commit

Permalink
ci(pre-commit): autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 16, 2024
1 parent 980bbcc commit b928df5
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ chess_board_detector:
adaptive_thresh: false
normalize_image: false
fast_check: false
resized_detection: false
resized_detection: false
resized_max_resolution: 1000
sub_pixel_refinement: true
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ chess_board_detector:
adaptive_thresh: false
normalize_image: false
fast_check: false
resized_detection: false
resized_detection: false
resized_max_resolution: 1000
sub_pixel_refinement: true
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ chess_board_detector:
adaptive_thresh: false
normalize_image: false
fast_check: false
resized_detection: false
resized_detection: false
resized_max_resolution: 1000
sub_pixel_refinement: true
sub_pixel_refinement: true
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ chess_board_detector:
adaptive_thresh: false
normalize_image: false
fast_check: false
resized_detection: false
resized_detection: false
resized_max_resolution: 1000
sub_pixel_refinement: true
sub_pixel_refinement: true
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,3 @@ def get_flattened_cell_sizes(self):

self._cached_flattened_cell_sizes = cell_sizes.flatten()
return self._cached_flattened_cell_sizes

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def get_linear_error_rms(self) -> float:
"""Return RMS error product of the projection of the lines of each row of the detection into the line produced by the first and line point of each row."""
raise NotImplementedError


def restart_linearity_heatmap(self):
"""Restart linearity heatmap."""
raise NotImplementedError
Expand Down Expand Up @@ -239,7 +238,7 @@ def get_speed(self, last: "BoardDetection") -> float:
last_image_points = last.get_flattened_image_points()

return np.linalg.norm(current_image_points - last_image_points, axis=-1).mean()

def get_aspect_ratio_pattern(self, model: CameraModel) -> float:
"""Get aspect ratio using the calibration pattern, which should be squared."""
tilt, pan = self.get_rotation_angles(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import time

import cv2
from intrinsic_camera_calibrator.board_detections.chess_board_detection import ChessBoardDetection
from intrinsic_camera_calibrator.board_detectors.board_detector import BoardDetector
from intrinsic_camera_calibrator.parameter import Parameter
from intrinsic_camera_calibrator.utils import to_grayscale
import numpy as np
import time


class ChessBoardDetector(BoardDetector):
Expand Down Expand Up @@ -59,7 +60,7 @@ def detect(self, img: np.array, stamp: float):
resized_detection = self.resized_detection.value
resized_max_resolution = self.resized_max_resolution.value

def get_roi(corners, frame_shape, padding = 120):
def get_roi(corners, frame_shape, padding=120):
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
x_min, y_min = max(0, x_min), max(0, y_min)
Expand All @@ -81,7 +82,7 @@ def get_roi(corners, frame_shape, padding = 120):
self.detection_results_signal.emit(img, None, stamp)
return
else:
roi_frame = grayscale[self.roi[1]:self.roi[3], self.roi[0]:self.roi[2]]
roi_frame = grayscale[self.roi[1] : self.roi[3], self.roi[0] : self.roi[2]]
(ok, corners) = cv2.findChessboardCorners(roi_frame, (cols, rows), flags=flags)
if ok:
corners += (self.roi[0], self.roi[1])
Expand All @@ -93,7 +94,9 @@ def get_roi(corners, frame_shape, padding = 120):
return

if self.roi:
cv2.rectangle(img, (self.roi[0], self.roi[1]), (self.roi[2], self.roi[3]), (0, 255, 0), 2)
cv2.rectangle(
img, (self.roi[0], self.roi[1]), (self.roi[2], self.roi[3]), (0, 255, 0), 2
)

else:
# Find the resized dimensions
Expand Down Expand Up @@ -164,5 +167,5 @@ def get_roi(corners, frame_shape, padding = 120):
object_points=object_points,
image_points=image_points,
)
print("detect_fcn: ", time.time()-st_time, flush=True)
print("detect_fcn: ", time.time() - st_time, flush=True)
self.detection_results_signal.emit(img, detection, stamp)
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def make_solver_group(self):

def on_calibrator_clicked():
self.current_calibrator_type = self.calibrator_type_combobox.currentData()

for calibrator_type in CalibratorEnum:
self.calibrator_type_combobox.addItem(calibrator_type.value["display"], calibrator_type)

Expand All @@ -266,7 +266,7 @@ def on_calibrator_clicked():

self.calibrator_type_combobox.currentIndexChanged.connect(on_calibrator_clicked)
self.current_calibrator_type = self.calibrator_type_combobox.currentData()

solver_layout = QVBoxLayout()
solver_layout.setAlignment(Qt.AlignTop)
solver_layout.addWidget(self.calibrator_type_combobox)
Expand Down Expand Up @@ -615,7 +615,7 @@ def start(
board_type: BoardEnum,
board_parameters: ParameterizedClass,
initial_intrinsics: CameraModel,
cfg : dict,
cfg: dict,
):
self.operation_mode = mode
self.data_source = data_source
Expand Down Expand Up @@ -647,7 +647,7 @@ def start(
calibrator.partial_calibration_results_signal.connect(
self.process_partial_calibration_result
)

# Qt logic
self.should_process_image.connect(self.process_data)
self.produced_data_signal.connect(self.process_new_data)
Expand Down Expand Up @@ -886,7 +886,7 @@ def save_parameters(self, filename):
calib_params = self.calibrator_dict[calibrator_type].get_parameters_values()
with open(filename, "w") as file:
yaml.dump({"board_parameters": board_params}, file, default_flow_style=False)
yaml.dump({"board_type" : self.board_type.value["name"]}, file, default_flow_style=False)
yaml.dump({"board_type": self.board_type.value["name"]}, file, default_flow_style=False)
yaml.dump(
{"calibrator_type": calibrator_type.value["name"]}, file, default_flow_style=False
)
Expand Down Expand Up @@ -949,7 +949,7 @@ def on_save_clicked(self):
def process_detection_results(self, img: np.array, detection: BoardDetection, img_stamp: float):
"""Process the results from an object detection."""
# Signal that the detector is free
print("elapsedtime_Debug: ", time.time()- self.time_for_debug, flush=True)
print("elapsedtime_Debug: ", time.time() - self.time_for_debug, flush=True)

Check warning on line 952 in calibrators/intrinsic_camera_calibrator/intrinsic_camera_calibrator/intrinsic_camera_calibrator/camera_calibrator.py

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (elapsedtime)
self.consumed_data_signal.emit()
self.time_for_debug = time.time()

Expand Down Expand Up @@ -997,7 +997,7 @@ def process_detection_results(self, img: np.array, detection: BoardDetection, im
self.indicators_alpha_spinbox.value(),
False,
)
self.skip_next_img = 3 # skips the next images if there are no detections
self.skip_next_img = 3 # skips the next images if there are no detections

else:
camera_model_cfg, camera_model_type = self.calibrator_dict[
Expand All @@ -1015,7 +1015,7 @@ def process_detection_results(self, img: np.array, detection: BoardDetection, im
mode=self.operation_mode,
)
# filter_result = CollectionStatus.REJECTED
print("dat_coll : ", time.time()-dat_coll_start, flush=True)
print("dat_coll : ", time.time() - dat_coll_start, flush=True)
else:
filter_result = CollectionStatus.NOT_EVALUATED

Expand Down Expand Up @@ -1086,7 +1086,7 @@ def process_detection_results(self, img: np.array, detection: BoardDetection, im
f"Linear error cols rms: {err_rms_cols:.2f} px" # noqa E231
)
self.aspect_ratio_label.setText(
f"Aspect Ratio: {detection.get_aspect_ratio_pattern(camera_model):.2f} px" # noqa E231
f"Aspect Ratio: {detection.get_aspect_ratio_pattern(camera_model):.2f} px" # noqa E231
)
self.rough_tilt_label.setText(
f"Rough tilt: {detection.get_tilt(camera_model):.2f} degrees" # noqa E231
Expand Down Expand Up @@ -1203,10 +1203,12 @@ def process_detection_results(self, img: np.array, detection: BoardDetection, im
detection_time = current_time - self.detection_request_time

if self.operation_mode == OperationMode.CALIBRATION:
self.setWindowTitle(f"Camera intrinsics calibrator ({self.data_source.get_camera_name()}). Data delay={detection_delay: .2f} Detection time={detection_time: .2f} fps={self.estimated_fps: .2f} Data time={img_stamp: .2f}"
self.setWindowTitle(
f"Camera intrinsics calibrator ({self.data_source.get_camera_name()}). Data delay={detection_delay: .2f} Detection time={detection_time: .2f} fps={self.estimated_fps: .2f} Data time={img_stamp: .2f}"
)
if self.operation_mode == OperationMode.EVALUATION:
self.setWindowTitle(f"Camera intrinsics Evaluation Mode ({self.data_source.get_camera_name()}). Data delay={detection_delay: .2f} Detection time={detection_time: .2f} fps={self.estimated_fps: .2f} Data time={img_stamp: .2f}"
self.setWindowTitle(
f"Camera intrinsics Evaluation Mode ({self.data_source.get_camera_name()}). Data delay={detection_delay: .2f} Detection time={detection_time: .2f} fps={self.estimated_fps: .2f} Data time={img_stamp: .2f}"
)

self.image_view.update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import yaml
from collections import defaultdict
import logging
import os

from PySide2.QtCore import Signal
from PySide2.QtWidgets import QComboBox
from PySide2.QtWidgets import QFileDialog
Expand All @@ -25,6 +26,7 @@
from PySide2.QtWidgets import QRadioButton
from PySide2.QtWidgets import QVBoxLayout
from PySide2.QtWidgets import QWidget
from ament_index_python.packages import get_package_share_directory
from intrinsic_camera_calibrator.board_parameters.board_parameters_factory import (
make_board_parameters,
)
Expand All @@ -39,8 +41,7 @@
from intrinsic_camera_calibrator.views.parameter_view import ParameterView
from intrinsic_camera_calibrator.views.ros_bag_view import RosBagView
from intrinsic_camera_calibrator.views.ros_topic_view import RosTopicView
from ament_index_python.packages import get_package_share_directory
import os
import yaml


class InitializationView(QWidget):
Expand All @@ -65,9 +66,9 @@ def __init__(self, calibrator: "CameraIntrinsicsCalibratorUI", cfg): # noqa F82
}

# Get the package share directory
package_share_dir = get_package_share_directory('intrinsic_camera_calibrator')
package_share_dir = get_package_share_directory("intrinsic_camera_calibrator")
# Get the path to the config directory
config_dir = os.path.join(package_share_dir, 'config')
config_dir = os.path.join(package_share_dir, "config")

self.layout = QVBoxLayout(self)

Expand All @@ -94,22 +95,19 @@ def __init__(self, calibrator: "CameraIntrinsicsCalibratorUI", cfg): # noqa F82
def on_params_combo_box_changed(index):
if self.params_combobox.currentText() == "Load File":
file_name, _ = QFileDialog.getOpenFileName(
self,
"Open File",
"",
"All Files (*.*);;Text Files (*.yaml)"
self, "Open File", "", "All Files (*.*);;Text Files (*.yaml)"
)
if file_name:
print(f"Selected file: {file_name}")
config_file_path = file_name
elif self.params_combobox.currentText() == "C1":
config_file_path = os.path.join(config_dir, 'c1_intrinsics_calibrator.yaml')
config_file_path = os.path.join(config_dir, "c1_intrinsics_calibrator.yaml")
elif self.params_combobox.currentText() == "C2":
config_file_path = os.path.join(config_dir, 'c2_intrinsics_calibrator.yaml')
config_file_path = os.path.join(config_dir, "c2_intrinsics_calibrator.yaml")
elif self.params_combobox.currentText() == "Ceres Calib":
config_file_path = os.path.join(config_dir, 'intrinsics_calibrator_ceres.yaml')
config_file_path = os.path.join(config_dir, "intrinsics_calibrator_ceres.yaml")
elif self.params_combobox.currentText() == "General":
config_file_path = os.path.join(config_dir, 'intrinsics_calibrator.yaml')
config_file_path = os.path.join(config_dir, "intrinsics_calibrator.yaml")

if config_file_path:
cfg = {}
Expand Down Expand Up @@ -238,7 +236,7 @@ def on_success():
board_type,
self.board_parameters_dict[board_type],
self.initial_intrinsics,
self.cfg
self.cfg,
)
self.close()

Expand Down

0 comments on commit b928df5

Please sign in to comment.