3

I am using Opencv in android and I want to load an image from gallery to Mat , please check my code and help in what I did wrong?

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult( requestCode, resultCode, data ); if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK) { Uri imageUri = data.getData(); String selectedImagePath = getPath(imageUri); Mat imgRgba = Imgcodecs.imread( selectedImagePath ); Mat img = new Mat(); imgRgba.copyTo(img); } private String getPath(Uri imageUri) { String[] projection = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query( imageUri, projection, null, null, null ); if(cursor!=null){ int column_index = cursor.getColumnIndexOrThrow( MediaStore.Images.Media.DATA ); cursor.moveToFirst(); return cursor.getString( column_index ); } return imageUri.getPath(); } 

When I run it it crashes with : java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.imgcodecs.Imgcodecs.imread_1(java.lang.String) (tried Java_org_opencv_imgcodecs_Imgcodecs_imread_11 and Java_org_opencv_imgcodecs_Imgcodecs_imread_11__Ljava_lang_String_2) at org.opencv.imgcodecs.Imgcodecs.imread_1(Native Method) at org.opencv.imgcodecs.Imgcodecs.imread(Imgcodecs.java:118)

7
  • How can someone figure out: "what I did wrong"? Without getting to know the issue you are facing? Are you getting an empty Mat? Are you getting an exception? Are you getting image of Justin Bieber, while reading Lena.png? Commented Jul 17, 2018 at 14:12
  • sorry the app crashes in this line Mat imgRgba = Imgcodecs.imread( selectedImagePath ); it says java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.imgcodecs.Imgcodecs.imread_1(java.lang.String) (tried Java_org_opencv_imgcodecs_Imgcodecs_imread_11 and Java_org_opencv_imgcodecs_Imgcodecs_imread_11__Ljava_lang_String_2) at org.opencv.imgcodecs.Imgcodecs.imread_1(Native Method) at org.opencv.imgcodecs.Imgcodecs.imread(Imgcodecs.java:118) Commented Jul 17, 2018 at 14:17
  • Search for ImgCodecs.java file in your project(tap double shift, Android Studio shortcut to search file). In that file search for imread() method, to see if it is present? and also note the signature of that method. Commented Jul 17, 2018 at 14:22
  • It seems wierd that other OpenCV API's are working fine but Imgcodecs.imread()is not :/ Commented Jul 17, 2018 at 14:23
  • yaa it's present : public static Mat imread(String filename, int flags) { Mat retVal = new Mat(imread_0(filename, flags)); return retVal; } Commented Jul 17, 2018 at 16:42

1 Answer 1

3

You hava to initialize OpenCV library before using on Android.

Call below code before use OpenCV

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, this, baseLoaderCallback); 

And then, below method will be callback.

 @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i(TAG, "OpenCV loaded successfully"); } break; default: { super.onManagerConnected(status); } break; } } 

};

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.