I am trying to find the average of an array of images in android using OpenCV.
However the result is a completely white image.
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;
}
This is how I create the Mats from bitmaps
//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);