【问题标题】:Android OpenCV Averaging ImagesAndroid OpenCV 平均图像
【发布时间】:2017-06-08 12:03:02
【问题描述】:

我正在尝试使用 OpenCV 在 android 中找到一组图像的平均值。

但是结果是全白的图像。

public static Mat averageAll(Mat[] matList){
        int type = matList[0].type();
        Mat avg = Mat.zeros(matList[0].height(),matList[0].width(),CV_32FC4);
        Log.i("avg",""+avg.height()+" "+avg.width()+" "+avg.depth()+" "+avg.type());
        for(int i=0;i<matList.length;i++){
            Log.i(""+i,""+matList[i].height()+" "+matList[i].width()+" "+matList[i].depth()+" "+matList[i].type());
            matList[i].convertTo(matList[i],CV_32FC4);
            Core.add(matList[i],avg,avg);
        }
        Core.divide(avg,new Scalar(matList.length),avg);
        avg.convertTo(avg,type);
        return avg;
    }

这就是我从位图创建垫子的方式

//imagesList is an arrayList of bitmaps
Mat[] matList = new Mat[imagesList.size()]
for(int k = 0; k<imagesList.size();k++){
    Mat m = new Mat();
    Utils.bitmapToMat(imagesList.get(k),m);
    matList[k]=m;
}
Mat alignedM = ImageProcessor.averageAll(matList);

【问题讨论】:

  • 如果没有 matList 中的 Mat 类型,我不能说太多。你期望结果是什么?请提供更多信息。
  • Mat 列表的类型与Utils.bitmapToMap() 的结果相同,我认为是CV_8U。在计算之前,我将它们转换为 CV_32FC4。图像是 RGB jpg。预期的结果是一幅图像,其像素值是 matList 中每个图像的对应像素的平均值。
  • 如果是RGB,不应该是CV_8UC3而不是CV_32FC4吗?
  • 在这种情况下会出现尺寸不匹配错误。
  • 是的,应该有。但我真的不明白你为什么要转换图像,有什么意义?

标签: android opencv


【解决方案1】:

我发现了问题。

问题在于Core.divide(avg,new Scalar(matList.length),avg);。 Scalar 类实际上是一个 4 元素向量。

转换成

Core.divide(avg,new Scalar(matList.length,matList.length,matList.length,matList.length),avg);

给出了想要的输出。

【讨论】:

    猜你喜欢
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2018-06-08
    • 2011-12-17
    • 1970-01-01
    相关资源
    最近更新 更多