i am working on an android project using opencv , i am creating a histogram for a black and white image (1-0 values on image file) . i am following some tutorials i found on internet on how to create the histogram . i am doing something like this

        ArrayList<Mat> list = new ArrayList<Mat>();
        list.add(mRgba);
        MatOfInt channels = new MatOfInt(0);
        Mat hist= new Mat();
        MatOfInt histSize = new MatOfInt(25);
        MatOfFloat ranges = new MatOfFloat(0f, 1f);
        Imgproc.calcHist(list, channels, new Mat(), hist, histSize, ranges);

Then i want to view the data on hist Mat, if i try something like this...

            for(int i = 0;i<25;i++){
            Log.e(TAG, "data "+i+" "+hist.get(i, 0));
        }

i get

>  data 0 [D@2be05908
   data 1 [D@2be0a138
   data 2 [D@2bdf9f48
   data 22 [D@2be06c70

that makes no sense to me. if i try a different approach, like

            byte buff[] = new byte[ hist.height()*hist.width() * hist.channels()];
            hist.get(0, 0, buff);

i get error about mat compatibility with mat.get function.

Is there any way to directly access the data on hist mat?

i am intrested in getting back all the data, not only man mix

有帮助吗?

解决方案

hist.get(i, 0) returns array of doubles. So you can try this:

for (int i = 0; i< 25; i++) {
    double[] histValues = hist.get(i, 0);
    for (int j = 0; j < histValues.length; j++) {
        Log.d(TAG, "yourData=" + histValues[j]);
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top