Ask Your Question

Revision history [back]

Cannot run...

package com.example.qwill.opencvtests;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;


import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.KeyPoint;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.DescriptorMatcher;
import org.opencv.features2d.Feature2D;
import org.opencv.features2d.FeatureDetector;
import org.opencv.features2d.Features2d;
import org.opencv.photo.Photo;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.utils.Converters;
import org.opencv.android.Utils;



import java.io.File;
import java.util.Vector;


public class MainActivity extends AppCompatActivity {

    FeatureDetector test;
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: //opencv is loaded!
                {

                    test = FeatureDetector.create(FeatureDetector.FAST); //feature detector goes here!

                    MatOfKeyPoint one = new MatOfKeyPoint();
                    MatOfKeyPoint two = new MatOfKeyPoint();

                    Mat image1, image2;
                    image1 = Imgcodecs.imread(ResourcesCompat.getDrawable(getResources(), R.drawable.one, null).toString());

                    image2 = Imgcodecs.imread(ResourcesCompat.getDrawable(getResources(), R.drawable.two, null).toString());

                    Mat imageOut = image1.clone();

                    test.detect(image1, one);
                    test.detect(image2, two);

                    DescriptorMatcher descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
                    MatOfDMatch matches = new MatOfDMatch();

                    descriptorMatcher.match(image1, image2, matches);
                    Features2d.drawMatches(image1, one, image2, two, matches, imageOut);

                    Bitmap bm = Bitmap.createBitmap(imageOut.cols(), imageOut.rows(), Bitmap.Config.ARGB_8888);
                    Utils.matToBitmap(imageOut, bm);
                    Log.d("TEST", " worked ");
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback))
        {
            Log.d("TEST", "Cannot connect to OpenCV Manager");
        }
    }
}

My first attempts to put all my code in onCreate just lead to a crash that said my program continues to close, so I googled that situation and found the callback resolve but I can't get the callback to work? i just get my error Cannot connect to OpenCV Manager. Help please.

Cannot run...

package com.example.qwill.opencvtests;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;


import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.KeyPoint;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.DescriptorMatcher;
import org.opencv.features2d.Feature2D;
import org.opencv.features2d.FeatureDetector;
import org.opencv.features2d.Features2d;
import org.opencv.photo.Photo;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.utils.Converters;
import org.opencv.android.Utils;



import java.io.File;
import java.util.Vector;


public class MainActivity extends AppCompatActivity {

    FeatureDetector test;
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: //opencv is loaded!
                {

                    test = FeatureDetector.create(FeatureDetector.FAST); //feature detector goes here!

                    MatOfKeyPoint one = new MatOfKeyPoint();
                    MatOfKeyPoint two = new MatOfKeyPoint();

                    Mat image1, image2;
                    image1 = Imgcodecs.imread(ResourcesCompat.getDrawable(getResources(), R.drawable.one, null).toString());

                    image2 = Imgcodecs.imread(ResourcesCompat.getDrawable(getResources(), R.drawable.two, null).toString());

                    Mat imageOut = image1.clone();

                    test.detect(image1, one);
                    test.detect(image2, two);

                    DescriptorMatcher descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
                    MatOfDMatch matches = new MatOfDMatch();

                    descriptorMatcher.match(image1, image2, matches);
                    Features2d.drawMatches(image1, one, image2, two, matches, imageOut);

                    Bitmap bm = Bitmap.createBitmap(imageOut.cols(), imageOut.rows(), Bitmap.Config.ARGB_8888);
                    Utils.matToBitmap(imageOut, bm);
                    Log.d("TEST", " worked ");
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback))
        {
            Log.d("TEST", "Cannot connect to OpenCV Manager");
        }
    }
}

My first attempts to put all my code in onCreate just lead to a crash that said my program continues to close, so I googled that situation and found the callback resolve but I can't get the callback to work? i just get my error Cannot connect to OpenCV Manager. Help please.

EDIT::::

Fixed the first issue..

Second issue::::

DescriptorMatcher descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

displays this error

java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.features2d.DescriptorMatcher.create_1(int) (tried Java_org_opencv_features2d_DescriptorMatcher_create_11 and Java_org_opencv_features2d_DescriptorMatcher_create_11__I)