calcHist always fails Android Opencv

asked 2015-11-15 08:06:26 -0500

VeTaLio gravatar image

Hi, i'm try do use calcHist,but always getting this exception:

CvException [org.opencv.core.CvException: cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/histogram.cpp:1427: error: (-215) csz == 0 || csz == dims in function void cv::calcHist(cv::InputArrayOfArrays, const std::vector<int>&, cv::InputArray, cv::OutputArray, const std::vector<int>&, const std::vector<float>&, bool)

My source code looks like:

int histSize = 256;
Imgproc.cvtColor(source, gray, Imgproc.colorBgra2gray);
Mat hist = new Mat(); //grayscale histogram
MatOfFloat Range = new MatOfFloat(0f,256f); 
MatOfInt histMatsize = new MatOfInt(256);
bool Accumulate = false;
List<Mat> ListMat = new ArrayList<Mat>();
ListMat.Add(gray);
MatOfInt channels = new MatOfInt(1,0);
Imgproc.CalcHist(ListMat, channels,new Mat(), hist, histMatSize, Range, Accumulate);

So via this post, i tried to change some things:

  int histSize = 256;
    Imgproc.cvtColor(source, gray, Imgproc.colorBgra2gray);
    Mat hist = new Mat(); //grayscale histogram
    MatOfInt histMatSize = new MatOfInt(256, 256, 256);
    bool Accumulate = false;
    List<Mat> ListMat = new ArrayList<Mat>();
    ListMat.Add(gray);
    MatOfInt channels = new MatOfInt(1,0);
    MatOfFloat ranges = new MatOfFloat(0.0f,256.0f, 0.0f, 256.0f, 0.0f, 256.0f);
    Imgproc.CalcHist(ListMat, channels,new Mat(), hist, histMatSize, ranges, Accumulate);

And didn't helped,what can i do to resolve my problem? Thanks!!

edit retag flag offensive close merge delete