Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

*java* api Histogram calculation

Hi! I have been trying to write a function to compute the 3D histogram of a color image. i am very new to OpenCV. I am unable to get the result. I am getting the following error

OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ......\src\opencv\modules\imgproc\src\histogram.cpp, line 1419 CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims ] at org.opencv.imgproc.Imgproc.calcHist_1(Native Method) at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775) at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82) at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:133) at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30) OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ......\src\opencv\modules\imgproc\src\histogram.cpp, line 1419 CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims ] at org.opencv.imgproc.Imgproc.calcHist_1(Native Method) at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775) at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82) at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:134) at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30) java.lang.NullPointerException at org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:2848) at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:135) at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30) -1.0

the code I had written was

    public static Mat getColorHistogram(String imgLocation)
{
    try
    {
        Mat img=new Mat();
        img=org.opencv.highgui.Highgui.imread(imgLocation);
        List<Mat> imagesList=new ArrayList<>();
        imagesList.add(img);
        //Mat tempChannel=new Mat(new Size(3,1),org.opencv.core.CvType.
        int histSizeArray[]={256,256,256};
        int channelArray[]={0,1,2};
        MatOfInt channels=new MatOfInt(channelArray);
        //mChannels = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) };
        Mat hist=new Mat();
        MatOfInt histSize=new MatOfInt(25);
        //histSize.fromArray(histSizeArray);
        //histSize = new MatOfInt(256);
        float hrangesArray[]={0.0f,255.0f};
        MatOfFloat ranges=new MatOfFloat(0.0f,255.0f);
        org.opencv.imgproc.Imgproc.calcHist(imagesList, channels,new Mat(), hist, histSize, ranges);
        return hist;
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return null;
    }
}

Here the line 82 corresponds to the calcHist line

*java* api Histogram calculation

Hi! I have been trying to write a function to compute the 3D histogram of a color image. i am very new to OpenCV. I am unable to get the result. I am getting the following error

OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ......\src\opencv\modules\imgproc\src\histogram.cpp, line 1419 CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims ] at org.opencv.imgproc.Imgproc.calcHist_1(Native Method) at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775) at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82) at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:133) at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30) OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ......\src\opencv\modules\imgproc\src\histogram.cpp, line 1419 CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims ] at org.opencv.imgproc.Imgproc.calcHist_1(Native Method) at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775) at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82) at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:134) at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30) java.lang.NullPointerException at org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:2848) at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:135) at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30) -1.0

the code I had written was

    public static Mat getColorHistogram(String imgLocation)
{
    try
    {
        Mat img=new Mat();
        img=org.opencv.highgui.Highgui.imread(imgLocation);
        List<Mat> imagesList=new ArrayList<>();
        imagesList.add(img);
        //Mat tempChannel=new Mat(new Size(3,1),org.opencv.core.CvType.
        int histSizeArray[]={256,256,256};
        int channelArray[]={0,1,2};
        MatOfInt channels=new MatOfInt(channelArray);
        //mChannels = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) };
        Mat hist=new Mat();
        MatOfInt histSize=new MatOfInt(25);
MatOfInt(256);
        //histSize.fromArray(histSizeArray);
        //histSize = new MatOfInt(256);
        float hrangesArray[]={0.0f,255.0f};
        MatOfFloat ranges=new MatOfFloat(0.0f,255.0f);
        org.opencv.imgproc.Imgproc.calcHist(imagesList, channels,new Mat(), hist, histSize, ranges);
        return hist;
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return null;
    }
}

Here the line 82 corresponds to the calcHist line

*java* api Histogram calculation

Hi! I have been trying to write a function to compute the 3D histogram of a color image. i am very new to OpenCV. I am unable to get the result. I am getting the following error

OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ......\src\opencv\modules\imgproc\src\histogram.cpp, ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp, line 1419
 CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\histogram.cpp:1419: ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims
 ]
     at org.opencv.imgproc.Imgproc.calcHist_1(Native Method)
     at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775)
     at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82)
     at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:133)
     at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30)
 OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ......\src\opencv\modules\imgproc\src\histogram.cpp, ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp, line 1419
 CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\histogram.cpp:1419: ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims
 ]
     at org.opencv.imgproc.Imgproc.calcHist_1(Native Method)
     at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775)
     at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82)
     at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:134)
     at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30)
 java.lang.NullPointerException
     at org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:2848)
     at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:135)
     at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30)
  -1.0

-1.0

the code I had written was

    public static Mat getColorHistogram(String imgLocation)
{
    try
    {
        Mat img=new Mat();
        img=org.opencv.highgui.Highgui.imread(imgLocation);
        List<Mat> imagesList=new ArrayList<>();
        imagesList.add(img);
        //Mat tempChannel=new Mat(new Size(3,1),org.opencv.core.CvType.
        int histSizeArray[]={256,256,256};
        int channelArray[]={0,1,2};
        MatOfInt channels=new MatOfInt(channelArray);
        //mChannels = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) };
        Mat hist=new Mat();
        MatOfInt histSize=new MatOfInt(256);
        //histSize.fromArray(histSizeArray);
        //histSize = new MatOfInt(256);
        float hrangesArray[]={0.0f,255.0f};
        MatOfFloat ranges=new MatOfFloat(0.0f,255.0f);
        org.opencv.imgproc.Imgproc.calcHist(imagesList, channels,new Mat(), hist, histSize, ranges);
        return hist;
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return null;
    }
}

Here the line 82 corresponds to the calcHist line

*java* api Histogram calculation

Hi! I have been trying to write a function to compute the 3D histogram of a color image. i am very new to OpenCV. I am unable to get the result. I am getting the following error

OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp, line 1419
CvException [org.opencv.core.CvException: ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims
]
dims]
    at org.opencv.imgproc.Imgproc.calcHist_1(Native Method)
    at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775)
    at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82)
    at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:133)
    at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30)
OpenCV Error: Assertion failed (csz == 0 || csz == dims) in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp, line 1419
CvException [org.opencv.core.CvException: ..\..\..\src\opencv\modules\imgproc\src\histogram.cpp:1419: error: (-215) csz == 0 || csz == dims
]
dims]
    at org.opencv.imgproc.Imgproc.calcHist_1(Native Method)
    at org.opencv.imgproc.Imgproc.calcHist(Imgproc.java:2775)
    at shikhar.logic.OpenCVTest.getColorHistogram(OpenCVTest.java:82)
    at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:134)
    at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30)
java.lang.NullPointerException
    at org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:2848)
    at shikhar.logic.OpenCVTest.compareImages(OpenCVTest.java:135)
    at shikhar.logic.OpenCVTest.main(OpenCVTest.java:30)
-1.0

the code I had written was

 public static Mat getColorHistogram(String imgLocation)
{
    try
    {
        Mat img=new Mat();
        img=org.opencv.highgui.Highgui.imread(imgLocation);
        List<Mat> imagesList=new ArrayList<>();
        imagesList.add(img);
        //Mat tempChannel=new Mat(new Size(3,1),org.opencv.core.CvType.
        int histSizeArray[]={256,256,256};
        int channelArray[]={0,1,2};
        MatOfInt channels=new MatOfInt(channelArray);
        //mChannels = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) };
        Mat hist=new Mat();
        MatOfInt histSize=new MatOfInt(256);
        //histSize.fromArray(histSizeArray);
        //histSize = new MatOfInt(256);
        float hrangesArray[]={0.0f,255.0f};
        MatOfFloat ranges=new MatOfFloat(0.0f,255.0f);
        org.opencv.imgproc.Imgproc.calcHist(imagesList, channels,new Mat(), hist, histSize, ranges);
        return hist;
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return null;
    }
}

Here the line 82 corresponds to the calcHist line