0
votes

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

1

1 Answers

0
votes

I tried to do some tricks with ILoaderCallbackInterface(implementation) :

  public class LoaderCallBackHelper: Java.Lang.Object,ILoaderCallbackInterface
    {
        public void OnManagerConnected(int p0)
        {
            switch (p0)
            {
                case LoaderCallbackInterface.Success: 
                    System.Console.WriteLine("Succes");
                    break;
                default:
                    this.OnManagerConnected(p0);
                    break;
            }
        }
        public void OnPackageInstall(int p0, IInstallCallbackInterface p1)
        {
            p1.Install();
            System.Console.WriteLine(p1.PackageName);
        }  

Then something like this(on MainActivity):

       ILoaderCallbackInterface t = new LoaderCallBackHelper();
 public  MainActivity()
        {
            if(OpenCVLoader.InitAsync(OpenCVLoader.OpencvVersion3000,this,t))
                {
                System.Console.WriteLine("OK");
                }
        }  

and no luck.
Then i tried to do other trick :

  public class BaseLoaderHelper : BaseLoaderCallback
    {
        public BaseLoaderHelper(Context context):base(context)
        {
        }
    }

        BaseLoaderCallback _t = new BaseLoaderHelper(this);
if(OpenCVLoader.InitAsync(OpenCVLoader.OpencvVersion3000,this,_t))
                    {
                    System.Console.WriteLine("OK");
                    }
            }   

And all was same,again OpenCV won't to initialise !
So my solution was that i downloaded OpenCV version 2.4.11 and reinstalled to my project. Now all works fines:

public  MainActivity()
        {
            if (!OpenCVLoader.InitDebug())
            {
                System.Console.WriteLine("Failed to INIT \n OpenCV Failure");
            }
            else
            {
                System.Console.WriteLine("OpenCV INIT Succes");
            }
        }