Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to show every image in every loop

I have such code

#include <opencv.hpp>
#include <filesystem>
using namespace cv;
using namespace std;

int main() {
    for (auto mark_name : experimental::filesystem::directory_iterator("E:/test")) {
        string filename = mark_name.path().string();
        Mat testImg = imread(filename.c_str(), 0);
        //Some steps about image-processing
        imshow(filename.c_str(), testImg);
    }
    waitKey();
    return 0;
    }

Suppose I have 10 or more image in my E:/test. I found all image have to show noramlly after all evaluation is completed, before that all window is gray status like this

I want the imshow(filename.c_str(), testImg); work to show the image directly in every loop, is possible?

How to show every image in every loop

I have such code

#include <opencv.hpp>
#include <filesystem>
using namespace cv;
using namespace std;

int main() {
    for (auto mark_name : experimental::filesystem::directory_iterator("E:/test")) {
        string filename = mark_name.path().string();
        Mat testImg = imread(filename.c_str(), 0);
        //Some steps about image-processing
        imshow(filename.c_str(), testImg);
    }
    waitKey();
    return 0;
    }

Suppose I have 10 or more image images in my driectory E:/test. I found all image have to show noramlly after all evaluation is completed, before that all window is gray status like this

I want the imshow(filename.c_str(), testImg); work to show the image directly in every loop, is possible?