【问题标题】:NullPointerException in javacvjavacv中的NullPointerException
【发布时间】: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


【解决方案1】:

错误在以下行:

featureDetector = FeatureDetector.create("SIFT");

我已将其替换为:

SIFT  sift = new SIFT();
FeatureDetector featureDetector =sift.getFeatureDetector();

【讨论】:

    猜你喜欢
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多