I'm using native android Opencv 3.0.0 library for Xamarin.Android via Android Java Bindings Library .
I'm doing pretty same like this Tutorial and the problem is that i got this exception
Native method not found: org.opencv.core.Mat.n_Mat:()J
What can i do to resolve this problem? Any help will be appreciated,thanks!
My source code of Main Activity :
public class MainActivity : Activity
{
Mat m;
Mat grayM;
ImageView imageView;
public MainActivity()
{
if (!OpenCVLoader.InitDebug())
{
System.Console.WriteLine("GG");
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.myButton);
ImageButton crop = FindViewById<ImageButton>(Resource.Id.crop);
crop.Visibility = ViewStates.Invisible;
imageView = FindViewById<ImageView>(Resource.Id.IMG);
if (IsThereAnAppToTakePictures ())
{
CreateDirectoryForPictures ();
button.Click += delegate
{
Intent intent = new Intent (MediaStore.ActionImageCapture);
App._file = new File (App._dir, String.Format("myPhoto_{0}.jpg", System.Guid.NewGuid()));
intent.PutExtra (MediaStore.ExtraOutput, Android.Net.Uri.FromFile (App._file));
StartActivityForResult (intent, 0);
crop.Visibility = ViewStates.Visible;
// SetImg();
};
}
crop.Click += (sender, e) =>
{
SetImg();
};
}
void SetImg()
{
using (Bitmap _img = BitmapFactory.DecodeFile(App._file.Path))
{
if (_img != null)
{
m = new Mat();
grayM = new Mat();
Utils.BitmapToMat(_img, m);
Imgproc.CvtColor(m, grayM, Imgproc.ColorBgr2gray);
Imgproc.CvtColor(grayM, m, Imgproc.ColorGray2bgra);
using (Bitmap bit = Bitmap.CreateBitmap(m.Cols(), m.Rows(), Bitmap.Config.Argb8888))
{
Utils.BitmapToMat(bit,m);
imageView.SetImageBitmap(bit);
}
m.Release();
grayM.Release();
}
}
}
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
// Make it available in the gallery
Intent mediaScanIntent = new Intent (Intent.ActionMediaScannerScanFile);
Android.Net.Uri contentUri = Android.Net.Uri.FromFile (App._file);
mediaScanIntent.SetData (contentUri);
SendBroadcast (mediaScanIntent);
imageView.SetImageBitmap(BitmapFactory.DecodeFile(contentUri.Path));
// Dispose of the Java side bitmap.
GC.Collect();
}
private void CreateDirectoryForPictures ()
{
App._dir = new File (
Android.OS.Environment.GetExternalStoragePublicDirectory (
Android.OS.Environment.DirectoryPictures), "CameraAppDemo");
if (!App._dir.Exists ())
{
App._dir.Mkdirs( );
}
}
private bool IsThereAnAppToTakePictures ()
{
Intent intent = new Intent (MediaStore.ActionImageCapture);
IList<ResolveInfo> availableActivities =
PackageManager.QueryIntentActivities (intent, PackageInfoFlags.MatchDefaultOnly);
return availableActivities != null && availableActivities.Count > 0;
}
}
public static class App
{
public static File _file;
public static File _dir;
public static Bitmap bitmap;
}
}
And Log of exception:
[MonoDroid] UNHANDLED EXCEPTION: [MonoDroid] Java.Lang.UnsatisfiedLinkError: Exception of type 'Java.Lang.UnsatisfiedLinkError' was thrown. [MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 [MonoDroid] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue*) [0x00084] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029 [MonoDroid] at Android.Runtime.JNIEnv.FinishCreateInstance (intptr,intptr,intptr,Android.Runtime.JValue*) [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:306 [MonoDroid] at Android.Runtime.JNIEnv.FinishCreateInstance (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x0001d] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:312 [MonoDroid] at Org.Opencv.Core.Mat..ctor () [0x000da] in