OpenCV 中的 accumulateWeighted 函数断言失败

accumulateWeighted function assertion fails in OpenCV

将 OpenCv 与 C++ 结合使用,我尝试对视频帧执行 运行 平均以提取前景。但是我无法找出 accumulateWeighted 函数有什么问题。当涉及到该函数时,程序停止 运行,并给出此错误:

Unhandled exception at 0x753b9617 in test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0017f0d4..

根据 OpenCV 文档,我看到 SRC 为 1 通道或 3 通道,应该是 8 位或 32 位浮点数。与SRC图像通道数相同的DST,应为32位或64位浮点数:

void accumulateWeighted(InputArray src, InputOutputArray dst, double alpha, InputArray mask=noArray())

所以我对他们两个都使用了CV_32F。我做错了吗?这是我的代码:

#include <iostream> // for standard I/O
#include <string>   // for strings
#include "stdafx.h"
#include <opencv.hpp>

#ifdef _DEBUG
#pragma comment (lib, "opencv_highgui2410d.lib")
#pragma comment (lib, "opencv_imgproc2410d.lib")
#pragma comment (lib, "opencv_core2410d.lib")
#else
#pragma comment (lib, "opencv_highgui2410.lib")
#pragma comment (lib, "opencv_imgproc2410.lib")
#pragma comment (lib, "opencv_core2410.lib")
#endif

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
//// Step 1 : Get ready to Capture Video

    VideoCapture cap("768x576.avi"); // open the video 

    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "Cannot open the video cam" << endl;
        return -1;
    }

//// Step 2 : Find video frame size 

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of          frames of the video

//// Step 3 : Running Average

    Mat sum=Mat::zeros(dHeight,dWidth,CV_32FC3);
    for (int iii=0;iii<100;iii++)  // for 100 frames
    {
        Mat frame_rgb,floatimg;

        bool bSuccess = cap.read(frame_rgb); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }

        frame_rgb.convertTo(floatimg, CV_32FC3);

        accumulateWeighted(floatimg,sum,0.03,NULL);
    }

    cap.release();

    return 0;    
}

也许尝试删除最后的 NULL?签名中的 noArray() 默认值与 NULL

不同