openCV垫的总和

时间:2015-02-16 15:35:10

标签: opencv addition mat

我正在尝试计算矩阵列表的平均值(逐个元素)。首先,我按元素执行sum元素,这是我正在使用的代码

 Mat imageResult = videoData[round(timestampInstImages[indexImg] * 100)];
 for (double frame = (timestampInstImages[indexImg] + timeBetweenFields); frame < (timestampInstImages[indexImg] + 1); frame += timeBetweenFields)
 {
     double roundedTimestamp = round(frame * 100);
     if (!videoData[roundedTimestamp].empty())
     {
          cout << "imageResult " << imageResult.at<int>(10,10) << endl;
          cout << "videoData[roundedTimestamp] " << videoData[roundedTimestamp].at<int>(10,10) <<endl;
          imageResult += videoData[roundedTimestamp];
          cout << "Result : " << imageResult.at<int>(10,10) << endl;
     }
 }

以下是我得到的输出的第一行:

imageResult 912924469
videoData[roundedTimestamp] 929701431
Result : 1842625900 //(912924469 + 929701431) It looks good
imageResult 1842625900
videoData[roundedTimestamp] 963386421
Result : -1493214815 // Not sure how the sum of 963386421 and 1842625900 returns this value???
imageResult -1493214815
videoData[roundedTimestamp] 963518006
Result : -536905769
imageResult -536905769

如上所述,总和有些不对劲。不确定它是什么。知道发生了什么吗?

1 个答案:

答案 0 :(得分:2)

将几个帧累积到'sum'帧中,你需要一个具有更大深度的帧,否则你会溢出(或饱和)它。

Mat acc(height,width,CV_32FC3,Scalar::all(0));

cv::accumulate(frame,acc);
cv::accumulate(frame,acc);
cv::accumulate(frame,acc);

acc /= 3;
Mat mean;
acc.convertTo(mean, CV_8UC3);