DeniseT DeniseT - 1 month ago 14
C++ Question

Increase every consecutive for loop

For now I have:

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


How can I make it so that the
for
loop values will increase every time it finishes looping. For example, after 10 images are accumulated and averaged, the loop will then automatically change to
for (framenumb = 10; framenumb < 20; ++framenumb)
to take the next 10 images and so on.

Answer

Something as simple as:

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

Where NUM is the number of images divided by 10.

Comments