*对不起,如果我的英语不好 - .-“
问候,
我是学生,只对OpenCV或Java有一点经验。我尝试制作一个程序,可以使用SIFT和RANSAC将两个图像拼接成一个全景图像。我还下载了OpenCV Library 2.4.6版本。
但是当我运行我的程序时,我得到了Null Pointer Exception:
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 :(得分:0)
试试这个:
MatOfDMatch matches = new MatOfDMatch();
sift1.detect(imgA, keypoint1,matches );
答案 1 :(得分: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);