C++ OpenCV c++;:absdiff中的参数错误(输入数组类型不同)

C++ OpenCV c++;:absdiff中的参数错误(输入数组类型不同),c++,opencv,C++,Opencv,我一直在尝试使用opencv进行速度估计。第一步是对图像进行灰度、模糊和精明处理,第二步是找出两者之间的绝对差异。 当找到绝对差异时,我得到以下结果: First scale conversion done: OpenCV Error: Bad argument (when the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be

我一直在尝试使用opencv进行速度估计。第一步是对图像进行灰度、模糊和精明处理,第二步是找出两者之间的绝对差异。 当找到绝对差异时,我得到以下结果:

First scale conversion done:

OpenCV Error: Bad argument (when the input arrays in add/subtract/multiply/divide 
functions have different types, the output array type must be explicitly specified)
in arithm_op, file /opt/opencv/modules/core/src/arithm.cpp, line 683.
terminate called after throwing an instance of 'cv::Exception'
这是我的密码:

#include <opencv2/videoio.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
Mat img,gray, blur, diff, tmp, canny, acc;
char first=0;

namedWindow("gray", CV_WINDOW_AUTOSIZE);
namedWindow("frame", CV_WINDOW_AUTOSIZE);


VideoCapture cap("toy_plane_liftoff.avi");
if(!cap.isOpened())
{
    printf("Error 404: no video found\n");
    return 0;
}
else printf("Capture from file successfull!!\n");

double fps = cap.get(CV_CAP_PROP_FPS);//bonus: frames per second counter
double frames= cap.get(CV_CAP_PROP_FRAME_COUNT);
double currentFrame = cap.get(CAP_PROP_FRAME_COUNT);
cout << "Frame per seconds : " << fps << "\n"<< "Total frames : " << frames << endl;

cap >>img;
acc = Mat::zeros(img.size(), CV_32FC3);

for(;;) {
cap >>img;

if (!cap.grab())
{
    cout << "\n Cannot read the frame from video file" << endl;
    break;
}

Mat floating;
img.copyTo(floating);


cvtColor(floating, gray, CV_RGB2GRAY);
GaussianBlur(gray, blur, Size(3,3), 0, 0, BORDER_DEFAULT );
Canny(blur, canny, 25, 150, 3);

if(first==0)
{
 canny.copyTo(diff);
 canny.copyTo(tmp);
 canny.convertTo(acc,CV_32FC3);
 printf("\n" "First scale conversion done \n \n");
 first=1;
}
else accumulateWeighted(canny, acc, 5, noArray());

acc.copyTo(tmp);
acc.convertTo(tmp,CV_32FC3);
absdiff(canny, tmp, diff);

imshow("gray", blur);
imshow("frame", tmp); //show vid
moveWindow("gray", 30, 100);
moveWindow("frame", 700, 100);

if(waitKey(10) == 27 ||waitKey(10)=='q')
  {
        cout << "press esc to eject!" << endl;
        break;
  }
}
return 0;
}


现在一切都“很好”

“输入数组是不同的类型”是的,看起来
canny
CV_8UC1
,而
tmp
CV_32FC3
。。。此外,您似乎对如何使用
copyTo
convertTo
感到非常困惑。使用调试器,看看发生了什么,如果你的矩阵和你期望的一样。@Miki你说得对,我很困惑,哈哈:(
acc.copyTo(tmp);
acc.convertTo(tmp,CV_32FC3);
convertScaleAbs(acc,tmp,1,0);