0

*对不起,如果我的英语不好-.-”

问候,

我是一名学生,对 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());

谢谢 :)

4

2 回答 2

0

尝试这个:

MatOfDMatch  matches = new MatOfDMatch();
sift1.detect(imgA, keypoint1,matches );
于 2013-12-25T10:40:34.597 回答
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);
于 2014-06-22T02:26:37.287 回答