Skip to content

Force load opencv before using OpenCV functions#1808

Merged
spacey-sooty merged 5 commits intoPhotonVision:mainfrom
Gold872:opencv-loading
Mar 13, 2025
Merged

Force load opencv before using OpenCV functions#1808
spacey-sooty merged 5 commits intoPhotonVision:mainfrom
Gold872:opencv-loading

Conversation

@Gold872
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Member

@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.

@spacey-sooty spacey-sooty merged commit f6736fc into PhotonVision:main Mar 13, 2025
36 checks passed
@Gold856 Gold856 added the photonlib Things related to the PhotonVision library label Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

photonlib Things related to the PhotonVision library

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