【发布时间】: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吗?
-
在这种情况下会出现尺寸不匹配错误。
-
是的,应该有。但我真的不明白你为什么要转换图像,有什么意义?