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

Force load opencv before using OpenCV functions #1808

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Gold872
Copy link

@Gold872 Gold872 commented Mar 11, 2025

Force loads OpenCV before any OpenCV functions are used. OpenCVLoader has all of its loading done in a static initializer field, so it's only loaded once.

Also deprecates OpenCVHelp.forceLoadOpenCV(), since it's functionality is the exact same.

Resolves #1803

@Gold872 Gold872 requested a review from a team as a code owner March 11, 2025 01:57
@mcm001
Copy link
Contributor

mcm001 commented Mar 11, 2025

When are these static blocks evaluated? Is there any way that they might end up only being evaluated once a robot begins autonomous.? Loading open CV can be pretty slow.

@Gold872
Copy link
Author

Gold872 commented Mar 11, 2025

When are these static blocks evaluated? Is there any way that they might end up only being evaluated once a robot begins autonomous.? Loading open CV can be pretty slow.

It should only happen when trying to update a pose estimator with a strategy that requires OpenCV, would you want these to be earlier like when the pose estimator is created?

@mcm001
Copy link
Contributor

mcm001 commented Mar 11, 2025

I don't know. I don't want teams not using these to pay the RAM cost, but also don't want a footgun for other people

@Gold872
Copy link
Author

Gold872 commented Mar 11, 2025

It should only happen when trying to update a pose estimator with a strategy that requires OpenCV, would you want these to be earlier like when the pose estimator is created?

Best I can do is both. It will load when the pose estimator is created with the necessary strategies, and before using the opencv functions just in case

Copy link
Contributor

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

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

Classloading in Java is lazy, so the static load will only happen when the class is first accessed. Checking for strategies that require OpenCV and then loading them if those strategies are used is exactly how I would've done it, and means only people who use those strategies will pay the cost of OpenCV.

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.

OpenCV library not loading on RoboRIO when using CONSTRAINED_SOLVEPNP pose strategy
4 participants