Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: skip frames, roi, fixed aspect ratio #225

Open
wants to merge 86 commits into
base: tier4/universe
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
7622989
Merge pull request #1 from tier4/tier4/universe
yabuta Jul 6, 2022
cdfddc0
Merge pull request #25 from tier4/tier4/universe
yabuta Aug 31, 2022
e1d3baa
[fix] speed filter option wrong type, added params to config camera c…
SergioReyesSan Nov 5, 2024
75ac158
[wip] functions to get training coverage percentage for skew, board size
SergioReyesSan Nov 5, 2024
8542655
[New] added UI indicators for speed, skew and size coverage of the board
SergioReyesSan Nov 5, 2024
ae33f40
[wip] Added Linear error rows/cols indicator
SergioReyesSan Nov 7, 2024
81aaf2f
[wip] manually fix problem loading intrinsics file, enabling disablin…
SergioReyesSan Nov 8, 2024
bd32252
[New] Added percentage linear error indicator rows cols
SergioReyesSan Nov 11, 2024
74c8227
Merge branch 'feature/indicators' into feature/intrinsics_evaluation_…
SergioReyesSan Nov 11, 2024
d6261a2
[New] Aspect ratio measurement and heatmap for linearity added
SergioReyesSan Nov 12, 2024
2539a4b
[New]Clear linearity hetmap, aspect ratio, board angles, save points …
SergioReyesSan Nov 19, 2024
cf3e90f
ci(pre-commit): autofix
pre-commit-ci[bot] Nov 19, 2024
ef16e47
[wip] Adding menu to load profile parameters
SergioReyesSan Nov 20, 2024
c5b1ea8
Fixing Typo errors an formatting
SergioReyesSan Nov 20, 2024
51b91ce
[Fix] Fixing more typo errors and spelling
SergioReyesSan Nov 20, 2024
ac6dea5
[Fix] disabling cspell for one line to pass check
SergioReyesSan Nov 20, 2024
c22e13e
[Fix] Removing capital from boolean yaml values because yamllint failure
SergioReyesSan Nov 20, 2024
39ff37d
Disabling rule:truthy for yamllint check
SergioReyesSan Nov 20, 2024
f05f89d
Merge branch 'feature/intrinsics_evaluation_mode' into feat/camera_pr…
SergioReyesSan Nov 20, 2024
7954185
Merge remote-tracking branch 'tier4/main' into feature/intrinsics_eva…
knzo25 Nov 26, 2024
b5acf20
Merge remote-tracking branch 'origin/tier4/universe' into feature/int…
knzo25 Nov 27, 2024
498cc45
fix: solved runtime errors but disabled some features
knzo25 Nov 27, 2024
fc83b36
[wip] menu to load 3 camera parameters profile
SergioReyesSan Nov 28, 2024
c8e8db0
Merge remote-tracking branch 'kenzo/feature/intrinsics_evaluation_mod…
SergioReyesSan Dec 2, 2024
316f694
Merge remote-tracking branch 'origin/tier4/universe' into feat/camera…
SergioReyesSan Dec 2, 2024
ef13c4c
[fix] eval mode working with new ceres solver, aspect ratio working
SergioReyesSan Dec 3, 2024
12e91d1
[New] Added set_parameters fcn to chessboard detection, params added …
SergioReyesSan Dec 3, 2024
a5d1965
[fix] fixed mistake on the previous commit when adding files
SergioReyesSan Dec 3, 2024
f2ad5cc
ci(pre-commit): autofix
pre-commit-ci[bot] Dec 3, 2024
50dff64
[wip] using roi and skip frames to improve performance
SergioReyesSan Dec 5, 2024
ee41821
[wip] forcing resize mode
SergioReyesSan Dec 5, 2024
62ed75a
[wip] removed change auto to resize mode tested on Anvil
SergioReyesSan Dec 5, 2024
43b9b92
[fix] not used variable was causing a failure
SergioReyesSan Dec 6, 2024
bce18ef
refactor: first changes according to the PR comments
SergioReyesSan Dec 11, 2024
185f319
ci(pre-commit): autofix
pre-commit-ci[bot] Dec 11, 2024
d8ab908
refactor: all comments form the discussion were addressed here
SergioReyesSan Dec 13, 2024
d1347cb
ci(pre-commit): autofix
pre-commit-ci[bot] Dec 13, 2024
8b6298a
wip: debugging k, d and some other params
SergioReyesSan Dec 18, 2024
959d2f8
fix: change precision of the data when saving intrinsic parameters, s…
SergioReyesSan Dec 20, 2024
ff5e7c0
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
f1eadd7
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
f1d3936
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
066acd1
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
9d33e68
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
ba0e889
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
2bda2c6
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
06c9829
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Dec 25, 2024
f89b3ff
fix: correcting misspelled
SergioReyesSan Dec 25, 2024
0b58b7e
refactor: cleaning a bit the code and fixing some lines of code
SergioReyesSan Dec 25, 2024
0bb8f19
Merge branch 'feat/camera_profiles' into perf/skip_frames_and_roi
SergioReyesSan Dec 25, 2024
5864ece
feat: Added new rectification to fix aspect ratio and skip images option
SergioReyesSan Dec 26, 2024
ec063e9
refactor: fixing some spelling errors
SergioReyesSan Dec 26, 2024
dfe5c0a
Merge branch 'feat/camera_profiles' into perf/skip_frames_and_roi to …
SergioReyesSan Dec 26, 2024
2b1a762
feat: change distortion model according to the number of distortion e…
SergioReyesSan Dec 27, 2024
d5015a4
refactor: change params calibration files
SergioReyesSan Jan 6, 2025
963d7f9
[wip] debugging segmentation fault using debugpy
SergioReyesSan Jan 9, 2025
8c9e3e4
fix: pause state due unhandled subpixel refinement exception, preven…
SergioReyesSan Jan 10, 2025
2f7ac75
refactor deleting comments
SergioReyesSan Jan 10, 2025
56c94dd
refactor: modifying default calibration parameters
SergioReyesSan Jan 10, 2025
c1e02c5
Merge remote-tracking branch 'origin/tier4/universe' into perf/skip_f…
SergioReyesSan Jan 10, 2025
1760894
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 10, 2025
d987f18
refactor: changing comment style
SergioReyesSan Jan 10, 2025
fb0201f
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 10, 2025
3238d30
refactor: removing spaces
SergioReyesSan Jan 13, 2025
e04b647
refactor: removing bank spaces
SergioReyesSan Jan 14, 2025
9f28974
refactor: returning original c1 params for reprojection error
SergioReyesSan Jan 17, 2025
6acce91
refactor: making normal variables as parameter
SergioReyesSan Jan 17, 2025
551da0c
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Jan 17, 2025
3025d32
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Jan 17, 2025
1cd430b
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 17, 2025
9a2f940
refactor: adding mutex to variable access
SergioReyesSan Jan 17, 2025
03a497c
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 17, 2025
9bc13bd
refactor: adding blank space and changing decimal precision when savi…
SergioReyesSan Jan 17, 2025
6b4888d
refactor: adding parameter for number of frames to skip
SergioReyesSan Jan 17, 2025
00c929a
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 17, 2025
c7026ec
refactor: adding enum for rectification options
SergioReyesSan Jan 17, 2025
96d89a3
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 17, 2025
bada59d
refactor: cached model restarts inside class
SergioReyesSan Jan 17, 2025
5781785
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 17, 2025
a2462e0
refactor: adding exclusion to cspell and blank space
SergioReyesSan Jan 17, 2025
6dca0a4
refactor: small refactor fot detect function
SergioReyesSan Jan 21, 2025
dab57a7
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 21, 2025
9dba948
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Jan 21, 2025
0133996
Update calibrators/intrinsic_camera_calibrator/intrinsic_camera_calib…
SergioReyesSan Jan 21, 2025
f0536e0
ci(pre-commit): autofix
pre-commit-ci[bot] Jan 21, 2025
63dfa77
refactor: small refactor and protecting value
SergioReyesSan Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ def draw_pointcloud(self, painter):
painter.drawEllipse if self.data_renderer.marker_type == "circles" else painter.drawRect
)

# print(f"Drawing pointcloud size: {scale_px.shape[0]}")

for point, radius, color_channel in zip(pointcloud_wcs, scale_px, color_scalars):
if self.data_renderer.color_channel == "intensity":
color = intensity_to_rainbow_qcolor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ void CeresCameraIntrinsicsOptimizer::solve()
ceres::Solver::Options options;
options.linear_solver_type = ceres::DENSE_SCHUR; // cSpell:ignore SCHUR
options.minimizer_progress_to_stdout = verbose_;
options.max_num_iterations = 500;
options.max_num_iterations = 100;
options.function_tolerance = 1e-10;
options.gradient_tolerance = 1e-14;
options.num_threads = 8;
options.max_num_consecutive_invalid_steps = 1000;
options.max_num_consecutive_invalid_steps = 100;
options.use_inner_iterations = true;
ceres::Solver::Summary summary;
ceres::Solve(options, &problem, &summary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ calibration_parameters:
use_ransac_pre_rejection: true # yamllint disable-line rule:truthy
pre_rejection_iterations: 100
pre_rejection_min_hypotheses: 6
pre_rejection_max_rms_error: 0.35
pre_rejection_max_rms_error: 0.5
knzo25 marked this conversation as resolved.
Show resolved Hide resolved
max_calibration_samples: 80
max_fast_calibration_samples: 20
use_entropy_maximization_subsampling: true # yamllint disable-line rule:truthy
subsampling_pixel_cells: 16
subsampling_tilt_resolution: 15.0
subsampling_max_tilt_deg: 45.0
use_post_rejection: true # yamllint disable-line rule:truthy
post_rejection_max_rms_error: 0.35
post_rejection_max_rms_error: 0.5
plot_calibration_data_statistics: true # yamllint disable-line rule:truthy
plot_calibration_results_statistics: true # yamllint disable-line rule:truthy
viz_pixel_cells: 16
Expand All @@ -43,13 +43,13 @@ data_collector:
max_allowed_pixel_speed: 10.0
max_allowed_speed: 0.1
filter_by_reprojection_error: true # yamllint disable-line rule:truthy
max_allowed_max_reprojection_error: 0.5
max_allowed_rms_reprojection_error: 0.3
max_allowed_max_reprojection_error: 2.0
max_allowed_rms_reprojection_error: 0.5
filter_by_2d_redundancy: true # yamllint disable-line rule:truthy
min_normalized_2d_center_difference: 0.05
min_normalized_skew_difference: 0.05
min_normalized_2d_size_difference: 0.05
filter_by_3d_redundancy: true # yamllint disable-line rule:truthy
filter_by_3d_redundancy: false # yamllint disable-line rule:truthy
min_3d_center_difference: 1.0
min_tilt_difference: 15.0
heatmap_cells: 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ calibration_parameters:
use_ransac_pre_rejection: true # yamllint disable-line rule:truthy
pre_rejection_iterations: 100
pre_rejection_min_hypotheses: 6
pre_rejection_max_rms_error: 0.35
pre_rejection_max_rms_error: 0.5
max_calibration_samples: 80
max_fast_calibration_samples: 20
use_entropy_maximization_subsampling: true # yamllint disable-line rule:truthy
subsampling_pixel_cells: 16
subsampling_tilt_resolution: 15.0
subsampling_max_tilt_deg: 45.0
use_post_rejection: true # yamllint disable-line rule:truthy
post_rejection_max_rms_error: 0.35
post_rejection_max_rms_error: 0.5
plot_calibration_data_statistics: true # yamllint disable-line rule:truthy
plot_calibration_results_statistics: true # yamllint disable-line rule:truthy
viz_pixel_cells: 16
Expand All @@ -40,8 +40,8 @@ data_collector:
max_allowed_pixel_speed: 10.0
max_allowed_speed: 0.1
filter_by_reprojection_error: true # yamllint disable-line rule:truthy
max_allowed_max_reprojection_error: 0.5
max_allowed_rms_reprojection_error: 0.3
max_allowed_max_reprojection_error: 2.0
max_allowed_rms_reprojection_error: 0.5
filter_by_2d_redundancy: true # yamllint disable-line rule:truthy
min_normalized_2d_center_difference: 0.05
min_normalized_skew_difference: 0.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ calibration_parameters:
use_ransac_pre_rejection: true # yamllint disable-line rule:truthy
pre_rejection_iterations: 100
pre_rejection_min_hypotheses: 6
pre_rejection_max_rms_error: 0.35
pre_rejection_max_rms_error: 0.5
max_calibration_samples: 80
max_fast_calibration_samples: 20
use_entropy_maximization_subsampling: true # yamllint disable-line rule:truthy
subsampling_pixel_cells: 16
subsampling_tilt_resolution: 15.0
subsampling_max_tilt_deg: 45.0
use_post_rejection: true # yamllint disable-line rule:truthy
post_rejection_max_rms_error: 0.35
post_rejection_max_rms_error: 0.5
plot_calibration_data_statistics: true # yamllint disable-line rule:truthy
plot_calibration_results_statistics: true # yamllint disable-line rule:truthy
viz_pixel_cells: 16
Expand All @@ -43,13 +43,13 @@ data_collector:
max_allowed_pixel_speed: 10.0
max_allowed_speed: 0.1
filter_by_reprojection_error: true # yamllint disable-line rule:truthy
max_allowed_max_reprojection_error: 0.5
max_allowed_rms_reprojection_error: 0.3
max_allowed_max_reprojection_error: 2.0
max_allowed_rms_reprojection_error: 0.5
filter_by_2d_redundancy: true # yamllint disable-line rule:truthy
min_normalized_2d_center_difference: 0.05
min_normalized_skew_difference: 0.05
min_normalized_2d_size_difference: 0.05
filter_by_3d_redundancy: true # yamllint disable-line rule:truthy
filter_by_3d_redundancy: false # yamllint disable-line rule:truthy
min_3d_center_difference: 1.0
min_tilt_difference: 15.0
heatmap_cells: 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ def detect(self, img: np.array, stamp):

def single_shot_calibration_error(self, object_points, image_points) -> Tuple[float, float]:
raise NotImplementedError

def restart_lost_frames_counter(self):
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

import cv2
from intrinsic_camera_calibrator.board_detections.chess_board_detection import ChessBoardDetection
from intrinsic_camera_calibrator.board_detectors.board_detector import BoardDetector
Expand All @@ -34,6 +36,12 @@ def __init__(self, **kwargs):
self.resized_max_resolution = Parameter(int, value=1000, min_value=500, max_value=3000)
self.sub_pixel_refinement = Parameter(bool, value=True, min_value=False, max_value=True)
self.set_parameters(**kwargs["cfg"])
self.roi = None
self.lost_frames = 0
self.max_lost_frames = 3
knzo25 marked this conversation as resolved.
Show resolved Hide resolved

def restart_lost_frames_counter(self):
self.lost_frames = self.max_lost_frames

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 @@ -54,15 +62,42 @@ 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):
knzo25 marked this conversation as resolved.
Show resolved Hide resolved
# 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
x_min, y_min = max(0, x_min), max(0, y_min)
x_max, y_max = min(frame_shape[1], x_max), min(frame_shape[0], y_max)
return (x_min, y_min, x_max, y_max)

h, w = img.shape[0:2]
grayscale = to_grayscale(img)

if not resized_detection or max(h, w) <= resized_max_resolution:
(ok, corners) = cv2.findChessboardCorners(grayscale, (cols, rows), flags=flags)

if not ok:
self.detection_results_signal.emit(img, None, stamp)
return
if self.roi is None or self.lost_frames >= self.max_lost_frames:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method became quite long and now has too many branches.
Can you either remove branches/indendation level via refactoring or split what can be split in smaller methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about how to refactor, i see we have the function find chessboard in common I can try to do something about it, I am not sure how clean it is going to look, but I will try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a bit of refactor here
dab57a7

(detected, corners) = cv2.findChessboardCorners(
grayscale, (cols, rows), flags=flags
)
# if chessboard was found, keep track of the region to try to detect easily in the next frame
if detected:
self.roi = get_roi(corners, img.shape[:2])
self.lost_frames = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.lost_frames is reset in a protected way now, but it is not here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm wrong, but we are protecting this value because it might change the max value on the UI side. So, is it necessary to add a lock here?

else:
self.lost_frames += 1
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]]
(detected, corners) = cv2.findChessboardCorners(
roi_frame, (cols, rows), flags=flags
)
if detected:
corners += (self.roi[0], self.roi[1])
self.roi = get_roi(corners, img.shape[:2])
self.lost_frames = 0
else:
self.lost_frames += 1
self.detection_results_signal.emit(img, None, stamp)
return
else:
# Find the resized dimensions
ratio = float(w) / float(h)
Expand Down Expand Up @@ -114,10 +149,16 @@ def detect(self, img: np.array, stamp: float):
)
np.fill_diagonal(dist_matrix, np.inf)
min_distance = dist_matrix.min()
radius = int(np.ceil(min_distance * 0.5))
radius = max(
1, int(np.ceil(min_distance * 0.5))
) # ensuring radius has a value of at least 1

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
corners = cv2.cornerSubPix(grayscale, corners, (radius, radius), (-1, -1), criteria)

try:
corners = cv2.cornerSubPix(grayscale, corners, (radius, radius), (-1, -1), criteria)
except Exception as e:
logging.error(e)

image_points = corners.reshape((rows, cols, 2))
x_array = cell_size * (np.array(range(cols)) - 0.5 * cols)
Expand All @@ -132,5 +173,4 @@ def detect(self, img: np.array, stamp: float):
object_points=object_points,
image_points=image_points,
)

self.detection_results_signal.emit(img, detection, stamp)
Loading
Loading