OpenCV4Android OpenCVManager missing java wrapper implementations

asked 2018-07-25 16:20:20 -0600

wmmc88 gravatar image

updated 2018-07-27 12:36:30 -0600

I've installed OpenCV4Android and OpenCVManager. I'm using OpenCV4Android 3.4.1 and OpenCVManager has downloaded both libopencv_java.so (2.4) and libopencv_java3.so (3.0).

When I make calls to Core.flip or create instances of Mat, it works as intended; however, when i make calls to Core.rotate, i get the following error:

07-25 17:15:10.252 5914-6018/com.example.wmmc88.traffictracker E/art: No implementation found for void org.opencv.core.Core.rotate_0(long, long, int) (tried Java_org_opencv_core_Core_rotate_10 and Java_org_opencv_core_Core_rotate_10__JJI) 07-25 17:15:10.253 5914-6018/com.example.wmmc88.traffictracker E/AndroidRuntime: FATAL EXCEPTION: Thread-3396 Process: com.example.wmmc88.traffictracker, PID: 5914 java.lang.UnsatisfiedLinkError: No implementation found for void org.opencv.core.Core.rotate_0(long, long, int) (tried Java_org_opencv_core_Core_rotate_10 and Java_org_opencv_core_Core_rotate_10__JJI) at org.opencv.core.Core.rotate_0(Native Method) at org.opencv.core.Core.rotate(Core.java:2043) at com.example.wmmc88.traffictracker.CameraActivity.onCameraFrame(CameraActivity.java:163) at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392) at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373) at java.lang.Thread.run(Thread.java:818)

When I use static initialization of the OpenCV library, it no longer gives me this error. It seems to me like the OpenCV Manager hasn't properly implemented some of the Core module's methods?

Code in Question:

public class CameraActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
    private static final String TAG = CameraActivity.class.getSimpleName();


    public static final int CAMERA_PERMISSION_REQUEST = 1;

    private Mat mRgba;

    private CameraBridgeViewBase mOpenCvCameraView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.activity_camera);

    }


    private boolean permissionsGranted() {
        Log.d(TAG, "checkpermissionsGranted");

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST);
            return false;
        }
        return true;
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        Log.d(TAG, "onRequestPermissionsResult");

        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case CAMERA_PERMISSION_REQUEST: {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Log.i(TAG, "Permissions Granted!");
                    loadOpenCVView();
                } else {
                    Log.w(TAG, "Permissions Denied!");
                    this.finish();
                }
                return;
            }

            //other permission request cases
        }
    }

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            Log.d(TAG, "onManagerConnected");
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i(TAG, "OpenCV loaded successfully");
                    if (permissionsGranted()) {
                        loadOpenCVView();
                    }
                }
                break;
                default: {
                    super.onManagerConnected(status);
                }
                break;
            }
        }
    };

    private void loadOpenCVView() {
        Log.d(TAG, "loadOpenCVView");

        mOpenCvCameraView = findViewById(R.id.cbvb_camera);
        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(this);
        mOpenCvCameraView.enableView();
    }


    @Override
    public void onResume() {
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, mLoaderCallback);
    }


    @Override
    public void onPause() {
        Log.d(TAG, "onPause");

        super.onPause();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    public void onDestroy() {
        Log.d(TAG, "onDestroy");

        super.onDestroy();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    public void onCameraViewStarted(int width, int height) {
        Log.d(TAG, "onCameraViewStarted");

        mRgba = new Mat(height, width, CvType.CV_8UC4);
    }

    public void onCameraViewStopped() {
        Log.d(TAG, "onCameraViewStopped");

        mRgba.release();
    }

    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        Log.d(TAG, "onCameraFrame");

        mRgba = inputFrame.rgba();

        Core.flip(mRgba, mRgba, 1); //Works

        Core ...
(more)
edit retag flag offensive close merge delete

Comments

we dont see your code, but likely, you're trying to use opencv code, before the dynamic loading finished.

berak gravatar imageberak ( 2018-07-25 23:41:46 -0600 )edit

I don't have the code handy rn, but if I replace core.rotate with core.flip, I don't get errors. I call it on the onCameraFrame callback and I only enable the view in the onManagerConnected callback.

wmmc88 gravatar imagewmmc88 ( 2018-07-25 23:58:59 -0600 )edit
1

@berak I've updated the post with the code

wmmc88 gravatar imagewmmc88 ( 2018-07-27 12:26:01 -0600 )edit