Force load opencv before using OpenCV functions (#1808)

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
This commit is contained in:
Gold87
2025-03-13 19:50:41 -04:00
committed by GitHub
parent 889c73ec91
commit f6736fc730
6 changed files with 28 additions and 12 deletions

View File

@@ -17,7 +17,7 @@
package org.photonvision.estimation;
import edu.wpi.first.cscore.CvSink;
import edu.wpi.first.cscore.OpenCvLoader;
import edu.wpi.first.math.MatBuilder;
import edu.wpi.first.math.Matrix;
import edu.wpi.first.math.Nat;
@@ -54,14 +54,12 @@ public final class OpenCVHelp {
private static final Rotation3d NWU_TO_EDN;
private static final Rotation3d EDN_TO_NWU;
// Creating a cscore object is sufficient to load opencv, per
// https://www.chiefdelphi.com/t/unsatisfied-link-error-when-simulating-java-robot-code-using-opencv/426731/4
private static CvSink dummySink = null;
/**
* @deprecated Replaced by {@link OpenCvLoader#forceStaticLoad()}
*/
@Deprecated(since = "2025", forRemoval = true)
public static void forceLoadOpenCV() {
if (dummySink != null) return;
dummySink = new CvSink("ignored");
dummySink.close();
OpenCvLoader.forceStaticLoad();
}
static {