累积加权函数断言在OpenCV中失败

时间:2015-04-19 14:25:20

标签: c++ opencv moving-average

使用OpenCv和C ++,我试图在视频帧上执行运行平均值来提取前景。但我无法找出accumulateWeighted函数的错误。程序停止运行时会出现此错误:

  

test.exe中0x753b9617处的未处理异常:Microsoft C ++异常:cv ::内存位置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;    
}

1 个答案:

答案 0 :(得分:1)

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

不同