Ask Your Question
0

How to read sequentially image files in OpenCv and C++ [closed]

asked 2016-12-05 05:56:01 -0600

KirtiSwagat gravatar image

updated 2016-12-05 06:17:07 -0600

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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by KirtiSwagat
close date 2016-12-19 05:44:21.250606

Comments

apart from VideoCapture(), - if you'dsave your files with leading zeros, like 00007.jpg, you could sort them properly

berak gravatar imageberak ( 2016-12-05 06:22:03 -0600 )edit

@berak how to do??? is there any modification required in my code.plz suggest

KirtiSwagat gravatar imageKirtiSwagat ( 2016-12-05 06:29:21 -0600 )edit

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 !

berak gravatar imageberak ( 2016-12-05 06:37:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-12-05 06:02:15 -0600

mshabunin gravatar image

Use cv::VideoCapture class, it supports described functionality - documentation, tutorial

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-05 05:56:01 -0600

Seen: 6,704 times

Last updated: Dec 05 '16