0

I have implemented openCv in my android project, project runs on device with api 23, correctly.

But just this project crashed on device with api 19. caused by:

java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:()J

so the question is, api 19 cant support openCV? or api 19 have a different config for openCV?

this is main part of my project:

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    OpenCVLoader.initDebug();
}

public void medianFilter(View view) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false; // Leaving it to true enlarges the decoded image size.
    Bitmap original = BitmapFactory.decodeResource(getResources(), R.drawable.test, options);

    Mat img1 = new Mat();
    Utils.bitmapToMat(original, img1);
    Mat medianFilter = new Mat();
    Imgproc.cvtColor(img1, medianFilter, Imgproc.COLOR_RGB2RGBA);

    Imgproc.median(medianFilter, medianFilter, 9);

    Bitmap imgBitmap = Bitmap.createBitmap(medianFilter.cols(), medianFilter.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(medianFilter, imgBitmap);

    ImageView imageView = findViewById(R.id.opencvImg);
    imageView.setImageBitmap(imgBitmap);
}}
SadeQ digitALLife
  • 1,403
  • 4
  • 16
  • 22

1 Answers1

0

A bit of more description of code where you've called medianFilter() could've been more informative, but as per the code you've mentioned.

I'd suggest to form your code as below in onResume():

@Override
public void onResume() {
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
    } else {
        Log.d(TAG, "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

Adding to the answer which i gave before

I'll try to consolidate below whatever i've tried to resolve this:

I tried to do some tricks with LoaderCallbackInterface:

public class LoaderCallBackHelper: Java.Lang.Object,ILoaderCallbackInterface
    {
        public void OnManagerConnected(int p0)
        {
            switch (p0)
            {
                case LoaderCallbackInterface.Success: 
                    System.Console.WriteLine("Success");
                    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");
                }
        }  

The issue still didn't resolve.

Then i tried some trick with

  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");
                    }
            }   

Still got the same error you've received.

My final solution to this was, 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 Success");
            }
        }

Try this way it should definitely work.

Omkar C.
  • 755
  • 8
  • 21
  • thanks for your response. by adding these lines app crashing solved, but now there is another problem with openCv manager thats not found and not found in google play. – SadeQ digitALLife Dec 02 '19 at 07:21
  • @SadeQdigitALLife could you please add the error you're receiving in the question you've asked stating 'updated code' – Omkar C. Dec 02 '19 at 10:57
  • I have wrote error text in my question. here is: java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:()J – SadeQ digitALLife Dec 02 '19 at 12:49
  • 1
    Hi @SadeQdigitALLife check above answer, i've updated it for you with whatever i've tried to resolve this issue. Hope this get sorted now. – Omkar C. Dec 02 '19 at 23:28