我正在尝试使用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);图像加载成功,我已经检查过了。有谁可以帮我?
发布于 2014-06-23 13:21:20
错误在以下行中:
featureDetector = FeatureDetector.create("SIFT");我将其替换为:
SIFT sift = new SIFT();
FeatureDetector featureDetector =sift.getFeatureDetector();https://stackoverflow.com/questions/24347396
复制相似问题