Engine
Engine

Reputation: 5422

how to calculate the mean value of multiple pictures

I'm trying to get the mean value of multiple pictures with opencv, here is my code :

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;

int main(){
    cv::Mat frame,frame32f;
    char filename[40];
    cv::Mat mean;
    const int count =10;
    const int width  = 1920;
    const int height = 1080;
    cv::Mat resultframe = cv::Mat::zeros(height,width,CV_32FC3);
    for(int i = 1 ; i<= count; i++){
        sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",i);
        frame = imread(filename,CV_LOAD_IMAGE_COLOR);
        frame.convertTo(frame32f,CV_32FC3);
        resultframe +=frame32f;
        cout << " i = " << i<<endl;
        frame.release();
    }
    resultframe *= (1.0/count);

    imshow("",resultframe);
    waitKey(0);
    return 0;
}

I get a always a white frame in imshow, any idea why do I get this. thanks in advance for your help !

Upvotes: 4

Views: 2225

Answers (1)

aardvarkk
aardvarkk

Reputation: 15996

Your problem may be that a standard RGB image uses unsigned char values, and thus has a range of [0,255]. I believe float images are expected to be in the range [0,1], so try doing:

resultframe *= (1.0/count/255)

Upvotes: 4

Related Questions