如何计算多张图片的平均值

4
我正在尝试使用OpenCV获取多张图片的平均值,以下是我的代码:

我正在尝试使用OpenCV获取多张图片的平均值,以下是我的代码:

#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;
}

我在imshow中总是会得到一个白框,你知道为什么会这样吗?非常感谢您的帮助!

1
我在之前的回答中告诉过你,如果您想要可视化浮点图像,它的值应该被标准化在0.0到1.0的范围内。 - sgarizvi
1个回答

4
您的问题可能是标准RGB图像使用无符号字符值,因此范围为[0,255]。我认为浮点图像应该在范围[0,1]内,请尝试执行以下操作: resultframe *= (1.0/count/255)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接