Reputation: 9
i am trying to extract SIFT features from an image using JavaCV and OpenCV
here is my code
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);
}
}
but the above code shows a NullPointerException on the line
featureDetector.detect(image,keypoints,null);
the image gets loaded successfully,i have checked. can anyone help me?
Upvotes: 0
Views: 363
Reputation: 9
The error was in the line:
featureDetector = FeatureDetector.create("SIFT");
I have replaced it with:
SIFT sift = new SIFT();
FeatureDetector featureDetector =sift.getFeatureDetector();
Upvotes: 1