gpt4 book ai didi

c++ - OpenCV 中的 accumulateWeighted 函数断言失败

转载 作者:行者123 更新时间:2023-11-28 06:18:41 25 4
gpt4 key购买 nike

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

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

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

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? about签名中的noArray()默认不等同于NULL

关于c++ - OpenCV 中的 accumulateWeighted 函数断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29731144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com