Ask Your Question

boom10611's profile - activity

2013-06-19 11:21:17 -0500 received badge  Supporter (source)
2013-06-18 21:24:21 -0500 received badge  Scholar (source)
2013-06-18 21:24:09 -0500 commented answer OpenCV4Android crashes when initializing Mat image

I found that I hadn't initialized my filePath1 string to the directory so I suppose that was the problem. I also added in the permission just in case. Thanks.

2013-06-18 13:35:22 -0500 received badge  Editor (source)
2013-06-18 13:09:07 -0500 received badge  Organizer (source)
2013-06-18 11:41:53 -0500 asked a question OpenCV4Android crashes when initializing Mat image

I'm using OpenCV4Android for a project. I think I've managed to set up the environment correctly, but when the code get's to this line:

image11 = Highgui.imread(filePath1,Highgui.IMREAD_GRAYSCALE);

It crashes and show's this error message:

VM aborting
Fatal signal 11 (SIGSEGV) at 0xdead00d (code=1), thread 1055 (mopencv_flann2)

EDIT: Here's the logcan output:

06-18 14:30:24.610: E/dalvikvm(8151): VM aborting
06-18 14:30:24.610: A/libc(8151): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 8151 (m.opencv_flann2)

I'm completely lost as to how to fix this and would appreciate some help. Here is all the code, with some this excluded:

public class FlannMainActivity extends Activity {   
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(final int status) {
        switch (status) {
        case LoaderCallbackInterface.SUCCESS:{
            _append ="Succelfully loaded OpenCV";
            _text.append(_append);
            image1 = Highgui.imread(filePath1, Highgui.IMREAD_GRAYSCALE);
            image1 = Highgui.imread(filePath2, Highgui.IMREAD_GRAYSCALE);
            descriptors1 = new Mat();
            descriptors2 = new Mat();
            extractor = DescriptorExtractor.create(DescriptorExtractor.SURF);
            featureDetector = FeatureDetector.create(FeatureDetector.SURF);
            keyPoint1 = new Vector<KeyPoint>();
            keyPoint2 = new Vector<KeyPoint>();
            matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
            matches = new Vector<DMatch>();
            goodMatches = new Vector<DMatch>();
            imgMatches = new Mat();

            if( !image1.empty() || !image2.empty()){
                _append = "ERROR: Cannot read an image";
                _text.append(_append);
            }

            List<Mat> imageMat = new Vector<Mat>();
            imageMat.add(image1);
            imageMat.add(image2);
            featureDetector.detect(imageMat, (List<MatOfKeyPoint>)(List<?>)keyPoint1);
            image1 = imageMat.get(0);
            image2 = imageMat.get(1);

            //Calculate descriptors (feature vectors)
            _append = "Calculate descriptors";
            _text.append(_append);
            List<Mat> discriptorMat = new Vector<Mat>();
            discriptorMat.add(descriptors1);
            discriptorMat.add(descriptors2);

            extractor.compute(imageMat, (List<MatOfKeyPoint>)(List<?>) keyPoint1, discriptorMat);

            //Matching descriptor vectors using FLANN matcher
            _append = "Matching descriptor vectors using FLANN matcher\n";
            _text.append(_append);
            double maxDist = 0, minDist = 100;

            matcher.radiusMatch(descriptors1, descriptors2, (List<MatOfDMatch>)(List<?>)matches, (float)maxDist);

            //Quick calculation of max and min distances between keypoints
            for(int i = 0; i < descriptors1.rows(); i++){
                final double dist = matches.get(i).distance;
                if(dist < minDist) minDist = dist;
                if(dist > maxDist) maxDist = dist;
            }

            _append = "-- Max dist: " + maxDist;
            _text.append(_append);
            _append = "-- Max dist: " + minDist;
            _text.append(_append);

            // Draw only "good" matches (i.e. whose distance is less than 2*minDist)
            // PS - radiusMatch can alco be used here

            for(int i = 0; i < descriptors1.rows(); i++) {
                if(matches.get(i).distance < 2*minDist) {
                    goodMatches.add(matches.get(i));
                }
            }

            //Draw only "good" matches
            final List<Character> m = new Vector<Character>();

            Features2d.drawMatches(image1, (MatOfKeyPoint) keyPoint1, image2, (MatOfKeyPoint) keyPoint2,
                    (MatOfDMatch) goodMatches, imgMatches, Scalar.all(-1), Scalar.all(-1),
                    (MatOfByte) m, Features2d.NOT_DRAW_SINGLE_POINTS);

            for(int i = 0; i < goodMatches.size(); i++){
                _append = "Good Match " + i + " Keypoint 1: " + goodMatches.get(i).queryIdx + " -- Keypoint 2 " + goodMatches.get(i).trainIdx + "\n";
                _text.append(_append);
            }
        }
        break;
        default: {
            super.onManagerConnected(status);
        }break;
        }
    }
}; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flann_main);

    if((!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_5, this, mLoaderCallback))) {
        _append = "Cannot connect to Open\n";
        _text.append(_append);
    }       

}