0

*sorry if my english is bad -.-"

Greetings,

I'm a student and only have a little experience with both OpenCV or Java. I try to make a program that can stitch two images into one panorama images using SIFT and RANSAC. I also downloaded OpenCV Library 2.4.6 version.

But when i run my program, i got the Null Pointer Exception in:

    sift1.detect(imgA, keypoint1);

Here's part of my program:

    fileA = getIntent().getStringExtra("fileA");
    fileB = getIntent().getStringExtra("fileB");

    imgA = Highgui.imread(fileA);
    Log.i("IMREAD", fileA+" berhasil");
    imgB = Highgui.imread(fileB);
    Log.i("IMREAD", fileB+" berhasil");

    FeatureDetector sift1 = FeatureDetector.create(3);
    sift1.detect(imgA, keypoint1);
    Log.d("keypoint", "jumlah keypoint 1 = " + keypoint1.size());

    FeatureDetector sift2 = FeatureDetector.create(3);
    sift2.detect(imgB, keypoint2);
    Log.d("keypoint", "jumlah keypoint 2 = " + keypoint2.size());

Thank you :)

  • Your question is similar to http://stackoverflow.com/questions/19716292/detecting-image-keypoints-javacv-exception-access-violation/19815128#19815128 – old-ufo Nov 06 '13 at 15:04

2 Answers2

0

Try this:

MatOfDMatch  matches = new MatOfDMatch();
sift1.detect(imgA, keypoint1,matches );
CRABOLO
  • 8,605
  • 39
  • 41
  • 68
user2084339
  • 41
  • 2
  • 4
0

The problem is in the line

FeatureDetector sift1 = FeatureDetector.create(3);

it should be

FeatureDetector siftDetector = FeatureDetector.create(FeatureDetector.SIFT);

also SIFT accepts image as grayscale image

Here is a sample example

public class sample 
{
public static void main(String[] args) 
{

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Mat image01 = Highgui.imread("C:/temp/313.jpg"); 

Mat grayImage01 = new Mat(image01.rows(), image01.cols(), image01.type());
Imgproc.cvtColor(image01, grayImage01, Imgproc.COLOR_BGRA2GRAY);
Core.normalize(grayImage01, grayImage01, 0, 255, Core.NORM_MINMAX);

FeatureDetector siftDetector = FeatureDetector.create(FeatureDetector.SIFT);
DescriptorExtractor siftExtractor = DescriptorExtractor.create(DescriptorExtractor.SIFT);

MatOfKeyPoint keyPoint01 = new MatOfKeyPoint();
siftDetector.detect(grayImage01, keyPoint01);