现在我有:

Mat avgImg(480, 640, CV_32FC3, Scalar()); // Create and zero initialize
Mat capturedImg;
for (framenumb = 0; framenumb < 10; ++framenumb)
{
    // avgImg.create(480, 640, CV_32FC3); // Don't create each time!
    capturedImg = images[framenumb];
    cv::accumulate(capturedImg, avgImg);
}
avgImg = avgImg / 100;
avgImg.convertTo(avgImg, CV_8UC3);
imshow("averaged", avgImg);

我该如何做,以便每次完成循环时for循环值都会增加。例如,在累积并平均10张图像之后,循环将自动更改为for (framenumb = 10; framenumb < 20; ++framenumb)以拍摄下10张图像,依此类推。

最佳答案

像这样简单:

for(int i = 0; i < NUM; i++) {
    Mat avgImg(480, 640, CV_32FC3, Scalar()); // Create and zero initialize
    Mat capturedImg;
    for (framenumb = 10 * i; framenumb < (10 * i) + 10; ++framenumb) {
        // avgImg.create(480, 640, CV_32FC3); // Don't create each time!
        capturedImg = images[framenumb];
        cv::accumulate(capturedImg, avgImg);
    }

    avgImg = avgImg / 100;
    avgImg.convertTo(avgImg, CV_8UC3);
    imshow("averaged", avgImg);
}

其中NUM是图片数除以10。

10-04 14:25