Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

calcHist java Null pointer Exception

$
0
0
Hi, I am new to openCV. Please help me resolve "null pointer exception" issue when I execute the below code. Thanks in advance. /** Program **/ import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfFloat; import org.opencv.core.MatOfInt; import org.opencv.imgproc.Imgproc; import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import static org.opencv.core.Core.split; import static org.opencv.imgcodecs.Imgcodecs.imread; public class Manu { static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); System.out.println("Executing library "+Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { System.out.println("Welcome to OpenCV " + Core.VERSION); Path p = null; try { p = Paths.get(new File(".").getCanonicalPath() + "/src/resource/ostracon - design.png"); } catch (IOException e) { e.printStackTrace(); } Mat src, dst; src = imread(p.toString()+" "); if(src.empty()){ System.out.println("Image could not be loaded.."); System.exit(1); } ArrayList rgb_planes = new ArrayList(3); split(src,rgb_planes); int histSize = 256; float range[] = {0,256}; float histRange[][] = {range}; boolean uniform = true; boolean accumulate = false; Mat rHist = null,gHist,bHist; Imgproc.calcHist(rgb_planes,new MatOfInt(1),new Mat(),rHist, new MatOfInt(histSize),new MatOfFloat(range),accumulate); } } **Error that I am facing -** Executing library opencv_java310 Welcome to OpenCV 3.1.0 Exception in thread "main" java.lang.NullPointerException at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:1487) at master.Manu.main(Manu.java:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Process finished with exit code 1

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>