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);
}
}
Please, post logcat output of this crash.