Created
January 8, 2019 06:08
-
-
Save junodeveloper/f30bb64c5d93434234f848111a28baad to your computer and use it in GitHub Desktop.
OpenCV load images from a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2/opencv.hpp" | |
#include <iostream> | |
#include <string> | |
using namespace cv; | |
using namespace std; | |
int main(int, char**) | |
{ | |
cv::String path("*.png"); | |
vector<cv::String> fn; | |
vector<Mat> data; | |
glob(path, fn, true); // recurse if true | |
for(size_t k=0; k<fn.size(); ++k) { | |
Mat im = imread(fn[k]); | |
if(im.empty()) continue; // continue if failed to load | |
data.push_back(im); | |
} | |
std::string base = "test"; | |
for(int i=0; i<data.size(); i++) { | |
std::string name = base + std::to_string(i+1); | |
namedWindow(name.c_str()); | |
imshow(name.c_str(), data[i]); | |
} | |
waitKey(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment