首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >javacv中的NullPointerException

javacv中的NullPointerException
EN

Stack Overflow用户
提问于 2014-06-22 09:33:02
回答 1查看 349关注 0票数 0

我正在尝试使用JavaCV和OpenCV从图像中提取SIFT特征

以下是我的代码

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
featureDetector.detect(image,keypoints,null);

图像加载成功,我已经检查过了。有谁可以帮我?

EN

回答 1

Stack Overflow用户

发布于 2014-06-23 13:21:20

错误在以下行中:

代码语言:javascript
运行
复制
featureDetector = FeatureDetector.create("SIFT");

我将其替换为:

代码语言:javascript
运行
复制
SIFT  sift = new SIFT();
FeatureDetector featureDetector =sift.getFeatureDetector();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24347396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档