2013-10-09 68 views
0

*对不起,如果我的英语不好-.-”空指针异常在OpenCV的SIFT特征检测器为Android

问候,

我是一个学生,只有既OpenCV的或缺乏经验Java我试图制作一个程序,可以将两个图像用SIFT和RANSAC拼接成一张全景图像,我也下载了OpenCV Library 2.4.6版本。 :

sift1.detect(imgA, keypoint1); 

这是我的计划的一部分:

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()); 

谢谢:)

+0

你的问题类似于http://stackoverflow.com/questions/19716292/detecting-image-keypoints- javacv的异常存取冲突/ 19815128#19815128 –

回答

0

试试这个:

MatOfDMatch matches = new MatOfDMatch(); 
sift1.detect(imgA, keypoint1,matches); 
0

的问题是在该行

FeatureDetector sift1 = FeatureDetector.create(3); 

它应该是

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

也SIFT接受图像作为灰度图像

下面是一个示例实施例

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);