OpenFTC / EasyOpenCV

Finally, a straightforward and easy way to use OpenCV on an FTC robot!
213 stars 95 forks source link

OpMode crashes on initialization when creating `OpenCvCamera` #50

Closed ariscript closed 1 year ago

ariscript commented 1 year ago

I currently have code like this that runs on initialization:

int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName()); // code makes it up to here
WebcamName webcamName = hardwareMap.get(WebcamName.class, RobotMap.Vision.WEBCAM); // crashes on this line
OpenCvCamera camera = OpenCvCameraFactory.getInstance().createWebcam(webcamName, cameraMonitorViewId);
camera.openCameraDeviceAsync(new OpenCvCamera.AsyncCameraOpenListener() {
    @Override
    public void onOpened() {
        camera.startStreaming(1280, 720, OpenCvCameraRotation.UPRIGHT);
        camera.setViewportRenderer(OpenCvCamera.ViewportRenderer.GPU_ACCELERATED);
        camera.setPipeline(new SimplePipeline());
    }
    @Override
    public void onError(int errorCode) {}
});

However, this code keeps crashing the OpMode with no error reported on the driver station. There are some errors reported in logcat:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/firstinspires/ftc/robotcore/internal/opmode/OpModeManagerImpl;
    at org.openftc.easyopencv.LIFO_OpModeCallbackDelegate.getInstance(LIFO_OpModeCallbackDelegate.java:42)
    at org.openftc.easyopencv.OpenCvCameraBase.<init>(OpenCvCameraBase.java:110)
    at org.openftc.easyopencv.OpenCvWebcamImpl.<init>(OpenCvWebcamImpl.java:102)
    at org.openftc.easyopencv.OpenCvCameraFactoryImpl.createWebcam(OpenCvCameraFactoryImpl.java:101)
    at org.firstinspires.ftc.teamcode.Robot.initCamera(Robot.java:76)
    ...
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.firstinspires.ftc.robotcore.internal.opmode.OpModeManagerImpl" on path: DexPathList[[zip file "/data/app/com.qualcomm.ftcrobotcontroller-2/base.apk"],nativeLibraryDirectories=[/data/app/com.qualcomm.ftcrobotcontroller-2/lib/arm, /data/app/com.qualcomm.ftcrobotcontroller-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        ... 18 more

I'm using FTCLib, so I followed the instructions here to install FTCLib and EOCV. Any help is appreciated. This is being run on a REV Control Hub with a USB Logitech webcam (using Android Studio).

Windwoes commented 1 year ago

This is almost certainly due to FTC Lib not using the latest version of EOCV.

SDK v8.0 broke compatibility with EOCV; this breakage was fixed in v1.5.2.

Windwoes commented 1 year ago

I messaged the FTC Lib maintainer on Discord; he will be trying to update FTCLib this weekend.

Closing this since it is not an issue with EOCV :')