gpt4 book ai didi

opencv - openCV中的总和

转载 作者:行者123 更新时间:2023-12-02 17:12:44 24 4
gpt4 key购买 nike

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

 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

正如您在上面看到的,总和中有一些错误。不知道是什么。知道发生了什么吗?

最佳答案

要将多个帧累积为一个“求和”帧,您需要一个深度较大的帧,否则将对其进行溢出(或饱和)。

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);

关于opencv - openCV中的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28544936/

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