2013-06-17 4 views
2

OpenCV-2.4.5-android-sdk를 사용하여 두 이미지를 기능 감지 (ORB 감지기 및 해밍 일치 도구)와 일치 시키려고합니다. Unfortunateley, 나는 설명자를 계산할 때 항상 NullPointerException을 얻고 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?OpenCV 2.4.5 android, FeatureDetector, DescriptorExtractor

 FeatureDetector detector = FeatureDetector.create("ORB"); 
     DescriptorExtractor descriptor = DescriptorExtractor.create("ORB"); 
     BFMatcher matcher = new BFMatcher(Hamming.normType, true); 

     KeyPoint keypoints1 = new KeyPoint(); 
     KeyPoint keypoints2 = new KeyPoint(); 
     CvMat[] descriptors = new CvMat[2]; 

     //ORB orb = new ORB(); 

     //orb.detect(image1, null, keypoints1); 
     detector.detect(image1, keypoints1, null); 
     descriptor.compute(image1, keypoints1, descriptors[0]); 

     detector.detect(image2, keypoints2, null); 
     //orb.detect(image2, null, keypoints2); 
     descriptor.compute(image2, keypoints2, descriptors[1]); 

     // matcher should include 2 different image's descriptors 
     DMatch matches = new DMatch(); 
     matcher.match(descriptors[0], descriptors[1], matches, null); 

android-ndk없이 Android에서 openCV로 기능 감지를 수행하는 변경 사항이 있으면 궁금합니다. 네이티브 C++ 코드를 작성하고 통합하려고 제안 하시겠습니까?

는 업데이트 :이 다음 프로젝트의 설정을 restructureing 후 : http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#dev-with-ocv-on-android 설명, 코드는 다음과 같습니다

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB); 
    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB); 
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING); 

    MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); 
    MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); 
    Mat[] descriptors = new Mat[2]; 

    //ORB orb = new ORB(); 
    //orb.detect(image1, null, keypoints1); 
    detector.detect(image1, keypoints1, null); 
    descriptor.compute(image1, keypoints1, descriptors[0]); 

    detector.detect(image2, keypoints2, null); 
    //orb.detect(image2, null, keypoints2); 
    descriptor.compute(image2, keypoints2, descriptors[1]); 

    // matcher should include 2 different image's descriptors 
    MatOfDMatch matches = new MatOfDMatch(); 
    matcher.match(descriptors[0], descriptors[1], matches); 

NPE가 계속 발생.

+0

난 당신이 descriptor.compute' '의 첫 번째 항목에서 예외가 있다고 가정합니다. CvMat [] 대신에'descriptors1'과'descriptors2' 두 개의 인스턴스를 갖도록하십시오. 도움이되지 않으면'detector.detect' 다음에 키포인트의 수를 인쇄 해보십시오. – JonesV

+0

답변 해 주셔서 감사합니다. 맞습니다. 오류는 'desriptor.compute'의 첫 번째 호출에서 발생합니다. 나는 두 개의 인스턴스'descriptors1'과'descriptors2'를 가지려고했지만 LogCat 출력을 얻었습니다 :'OpenCV Error : cv :: Mat cv :: cvarrToMat (const CvArr *, bool, bool, int), file /home/saudet/projects/javacv-cppjars/opencv-2.4.5/modules/core/src/matrix.cpp, line 698' 필자의 테스트 예제에서 keypoints1의 크기는'detect.detect' 이후 31이었다. 이것이 키포인트의 수인지 확실하지 않습니다. – Julia

+0

'CvMat' 대신에'Mat'을 사용하여 이미지와 디스크립터를 저장하려 했습니까? 'CvMat'은 이제 폐기되었습니다; 대신에'Mat'을 사용해보십시오. 이 예외로 인해 문제가 해결 될 수 있습니다. – Alexey

답변

1

descriptors[] 배열에 개체를 할당하지 못한 것 같습니다.

descriptors[0] = new CvMat(); 
    descriptors[1] = new CvMat(); 
0

개체를 할당합니다.

Mat descriptortwo = new Mat(); 

한 다음과 같이, 선택적인 마스크 매개 변수에서 null 인수를 제거 :

detector.detect(image1,keypoints1); 

0

시도가 thouse 매트릭스를 initializate하기 :) 트릭을한다고 생각합니다. 대신 말하는 Mat[] descriptors = new Mat[2];

시도 : Mat descriptors1= new Mat(); Mat descriptors2= new Mat();