Using OpenCV with WPILib in Java

I am trying to use SURF feature matching in opencv for object tracking as a vision experiment. It is located under xfeatures2d in opencv, which isn’t included in the wpilib install of opencv. When I try to import it, it says “The import org.opencv.xfeatures2d cannot be resolved”. I have tried to install opencv separately but it hasn’t fixed the problem. Is it possible to use 3rd party libraries that aren’t made for frc with wpilib? If so, how?

It’s possible to use WPILib with a different OpenCV installation, but not when using Gradle, because in Gradle, WPILib uses our OpenCV artifacts.

Is this on desktop or a coprocessor? You can build WPILib yourself using cmake to use an alternative OpenCV, but note it’s also critical for whatever OpenCV build you are using to also have installed the Java bindings.

2 Likes

This is on desktop. I will try to build WPILib myself and I’ll leave an update here on the results. Thanks for the information

UPDATE:
I was able to fix the problem by using this: https://github.com/bytedeco/javacv
I added implementation group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.7' under the dependencies in build.gradle and I was able to import the features I needed and the code builds fine now.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.