I want to calculate the average value of a sequence of frames by adding them, and then divide by the total number of frames. The problem is that I cannot access the pixels of the image. I used this code.
for(i = 1; i <= N; i++){
image = imread(fileName.c_str(),0);
Mat Mean = Mat::zeros(width, height,image.type());
for(w = 0; w < image.rows ; w++)
for(h = 0; h < image.cols ; h++)
Mean.row(w).col(h) += (image.at<unsigned float>(w,h) / N);
}
I always have an error confirming the statement. I also tried:
(float)image.at<uchar>(w,h)
image.row(w).col(h)[0]
image.row(w).col(h).val[0]
but in vain.
Here is the working code ... but I can not display the final result because it floats.
Mat Mean = Mat::zeros(width, height,CV_32F);
for(i = 1; i <= framesToLearn ; i++){
image = imread(fileName.c_str(),0);
accumulate(image, Mean);
}
Mean = Mean /framesToLearn;
imshow("mean",Mean);
waitKey(0);
source
share