我正在运行以下代码来计算从 OpenCV 上的视频中读取的一组图像的运行平均值。
编辑:(代码更新)
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/video.hpp"
using namespace std;
using namespace cv;
int main(int argc, char *argv[]) {
if(argc < 2) {
printf("Quitting. Insufficient parameters\n");
return 0;
}
char c;
int frameNum = -1;
const char* WIN_MAIN = "Main Window";
namedWindow(WIN_MAIN, CV_WINDOW_AUTOSIZE);
VideoCapture capture;
capture.open(argv[1]);
Mat acc, img;
capture.retrieve(img, 3);
acc = Mat::zeros(img.size(), CV_32FC3);
for(;;) {
if(!capture.grab()) {
printf("End of frame\n");
break;
}
capture.retrieve(img, 3);
Mat floating;
img.convertTo(floating, CV_32FC3);
accumulateWeighted(floating, acc, 0.01);
imshow(WIN_MAIN, img);
waitKey(10);
}
return 0;
}
在使用示例视频运行代码时,会弹出以下错误
OpenCV Error: Assertion failed (dst.size == src.size && dst.channels() == cn) in accumulateWeighted, file /usr/lib/opencv/modules/imgproc/src/accum.cpp, line 430
terminate called after throwing an instance of 'cv::Exception'
what(): /usr/lib/opencv/modules/imgproc/src/accum.cpp:430: error: (-215) dst.size == src.size && dst.channels() == cn in function accumulateWeighted
Aborted (core dumped)
错误的可能原因是什么?你能指导我正确的方向吗?
使用的编译器:g++ OpenCV 版本:2.4.5
谢谢!