【发布时间】:2014-08-12 09:35:27
【问题描述】:
我正在尝试使用 JavaCV 和 OpenCV 从图像中提取 SIFT 特征
这是我的代码
import java.io.File;
import com.googlecode.javacv.cpp.opencv_core.CvMat;
import com.googlecode.javacv.cpp.opencv_features2d.DescriptorExtractor;
import com.googlecode.javacv.cpp.opencv_features2d.FeatureDetector;
import com.googlecode.javacv.cpp.opencv_features2d.KeyPoint;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImageM;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_GRAYSCALE;
public class test {
static FeatureDetector featureDetector;
static DescriptorExtractor descriptorExtractor;
public static void main(String[] args)
{
featureDetector = FeatureDetector.create("SIFT");
descriptorExtractor=DescriptorExtractor.create("SIFT");
File file=new File("C:\\temp\\305.jpg");
CvMat image= cvLoadImageM(file.getAbsolutePath(),CV_LOAD_IMAGE_GRAYSCALE);
if(image==null)
System.out.println("image is null");
KeyPoint keypoints = new KeyPoint(null);
featureDetector.detect(image,keypoints,null);
CvMat featurs = new CvMat(null) ;
descriptorExtractor.compute(image, keypoints, featurs);
System.out.println(featurs);
}
}
但是上面的代码显示了一个 NullPointerException 就行了
featureDetector.detect(image,keypoints,null);
图片加载成功,我已经检查过了。 谁能帮帮我?
【问题讨论】:
-
如果空指针来自该行,则表明 featureDetector 为空。您是否尝试过单步执行代码?
-
是的,我试过了,但没有成功
标签: java android opencv javacv sift