从Mat,opencv android获取直方图数据 [英] get histogram data from Mat , opencv android

查看:177
本文介绍了从Mat,opencv android获取直方图数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv在android项目上工作,我正在为黑白图像(图像文件上的1-0值)创建直方图. 我正在跟踪我在互联网上找到的一些有关如何创建直方图的教程.我正在做这样的事情

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);

然后,如果我尝试这样的操作,我想查看hist Mat上的数据...

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));
        }

我明白了

>  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);

我遇到关于mat.get函数与mat兼容的错误.

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)返回双精度数组. 因此,您可以尝试以下操作:

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]);
    }
}

这篇关于从Mat,opencv android获取直方图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆