How to read sequentially image files in OpenCv and C++ [closed]
Suppose I have 7 numbers of ".jpg" files in a folder. All the names are numeric that is 0.jpg, 4.jpg, 1.jpg etc. How to read the files sequentially according to there name incrementally. That is first 0.jpg then 1.jpg then 4.jpg will be read.
I have tried with glob( ) function but image read is not sequentially..
#include <opencv2/opencv.hpp>
#include<iostream>
#include <dirent.h>
using namespace std;
using namespace cv;
int main()
{
String folder = "*.jpg";
vector<String> filenames;
glob(folder, filenames);
cout<<filenames.size()<<endl;//to display no of files
for(size_t i=0; i<filenames.size(),++i)
{
cout<<filenames[i]<<endl;
}
}
and the output is as follows 7 // no of files in the folder ./0.jpg ./11.jpg ./14.jpg ./2.jpg ./6.jpg ./8.jpg ./9.jpg
apart from VideoCapture(), - if you'dsave your files with leading zeros, like 00007.jpg, you could sort them properly
@berak how to do??? is there any modification required in my code.plz suggest
you'd need to modify your saving code, so it eg. uses
format("%05d".jpg)
for the filename, then you can just std::sort() the filenames vector from glob.but again, try with VideoCapture first !