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 80 commits into
base: tier4/universe
Choose a base branch
from

Conversation

SergioReyesSan
Copy link
Contributor

Description

This PR includes:

-ROI to keep track of the calibration board, making future detections faster (performance improvement).
-Will skip board detection on some future frames, if the board was not detected on the current frame (avoid long queues).
-Increase the decimal digits when saving intrinsic parameters, to avoid the bubble effect when rectifying the image.
-Fix the issue that suddenly was pausing the operation of the calibration tool.
-Implements a new method to fix the aspect ratio on the rectified image.
-Changes the distortion model according to the number of distortion coefficients.

Related links

Tests performed

Tested mainly on an x86 platform and using rosbags, but also non-extensive tests on anvil were performed.

Notes for reviewers

It might have some spelling errors, please let me know.

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

  • The PR follows the pull request guidelines.
  • The PR has been properly tested.
  • The PR has been reviewed by the code owners.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

  • There are no open discussions or they are tracked via tickets.
  • The PR is ready for merge.

After all checkboxes are checked, anyone who has write access can merge the PR.

yabuta and others added 30 commits July 6, 2022 16:18
copy calibration tools from private repository
merge main for galactic release
…and calibration parameters into a file, change ui elements in eval mode.
…rinsics_evaluation_mode

Signed-off-by: Kenzo Lobos-Tsunekawa <[email protected]>
@SergioReyesSan
Copy link
Contributor Author

just fixed it by removing some blank spaces

@SergioReyesSan SergioReyesSan requested a review from knzo25 January 14, 2025 02:17
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the Parameter class

Copy link
Collaborator

Choose a reason for hiding this comment

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

When you do, you need to change the restart_lost_frames_counter as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 = self.max_lost_frames.value
Access need to be protected by a mutex if I remember correctly

Copy link
Collaborator

Choose a reason for hiding this comment

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

applies to self.padding.value as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it better to have the padding as an absolute value? relative to the size of the image?
Any way, please use the Parameter class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@SergioReyesSan SergioReyesSan Jan 17, 2025

Choose a reason for hiding this comment

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

yes, it might be better to make it relative to the image size, I will try to do it later but to solve this asap just made it a parameter.
6acce91

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same concern as before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

@@ -992,6 +1012,7 @@ def process_detection_results(self, img: np.array, detection: BoardDetection, im
alpha_indicators=self.indicators_alpha_spinbox.value(),
value=False,
)
self.skip_next_img = 5 # skips the next images if there are no detections
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make this into a parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -165,6 +167,12 @@ def make_mode_group(self):

self.image_view_type_combobox.setEnabled(False)

self.rectify_label = QLabel("Rectify option:")
self.rectify_type_combobox = QComboBox()
self.rectify_type_combobox.addItem("Opencv", 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not like we are likely to add more rectification options, but for consistency, please use the Enums that are used throughout this package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -220,10 +228,14 @@ def on_evaluation_sample_changed(index):
img = self.data_collector.get_evaluation_image(index)
self.process_db_data(img)

def on_rectify_type_change(index):
self.calibrated_camera_model._cached_undistorted_model = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Variables with _ as a prefix indicate that they should not be modified from the outside

Copy link
Contributor Author

Choose a reason for hiding this comment

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

create a function that does the same, but inside the class
a2462e0

and self.skip_next_img > 1
and self.data_source_type != DataSourceEnum.FILES
):
self.detector.restart_lost_frames_counter() # to force next frame detection
Copy link
Collaborator

Choose a reason for hiding this comment

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

The detector acts in another thread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a mutex inside the function to make it safe
9bc13bd

return

if self.data_source_type == DataSourceEnum.FILES:
self.detector.restart_lost_frames_counter() # to force next frame detection
Copy link
Collaborator

Choose a reason for hiding this comment

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

The detector acts in another thread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a mutex inside the function to make it safe
9bc13bd

Copy link
Collaborator

@knzo25 knzo25 left a comment

Choose a reason for hiding this comment

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

Left some comments, but we still need to discuss the correctness of the rectification method

@SergioReyesSan
Copy link
Contributor Author

Left some comments, but we still need to discuss the correctness of the rectification method

I was checking a book that has a good explanation of the rectification process, and the equations used on the undistortion map seem to be good,

https://amroamroamro.github.io/mexopencv/matlab/cv.initUndistortRectifyMap.html

https://books.google.ch/books?id=seAgiOfu2EIC&lpg=PA373&pg=PA373#v=onepage&q&f=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants