Reputation: 27
I wanted to implement Gabor Filter with opencv in java in eclipse environment :
public static void main( String[] args ) throws IOException
{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat mat = Highgui.imread("./img/lena.jpg");
Mat dst =new Mat();
Imgproc.cvtColor(mat, dst, Imgproc.COLOR_RGB2GRAY);
dst.convertTo(source_f, CvType.CV_64F, (1.0/255) , 0.0);
.
.
.
}
But when it use convertTo Function, it display with error :
Exception in thread "main" java.lang.NullPointerException
at org.opencv.core.Mat.convertTo(Mat.java:959)
at testOpenCV.GaborFilter.main(GaborFilter.java:175)
I searched about that and tried display Mat object to knew where it was null but couldn't.
How can I fix it, please or even know where the null is?
Upvotes: 1
Views: 1198
Reputation: 51847
I don't see a declaration of source_f
in the snippet you posted. You might want to initialize source_f before pointing to it using convertTo
, perhaps something like:
Mat dst = new Mat();
Mat source_f = new Mat();
Imgproc.cvtColor(mat, dst, Imgproc.COLOR_RGB2GRAY);
dst.convertTo(source_f, CvType.CV_64F, (1.0/255) , 0.0);
Unfortunately I haven't used the java api much, so not 100% sure the syntax is correct.
Also, it's a good idea to go step by step and test your assumptions:
imread
), if so, display it on screen ?dst
correctly displaying the pixels after the gray scale conversion ?Upvotes: 2