gpt4 book ai didi

java - javacv 中的 NullPointerException

转载 作者:行者123 更新时间:2023-12-01 12:49:29 27 4
gpt4 key购买 nike

我正在尝试使用 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 = FeatureDetector.create("SIFT");

我已将其替换为:

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

关于java - javacv 中的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24347396/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com