Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

as @sturkmen pointed out before, you're reading all of your images into the same (global) Mat image, so you end up with identical copies of the last image read in your vector.

then, trying to read all files into memory is terribly inefficient, rather use a short fifo for the last N frames, and process on-the-fly:

#include <deque>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    deque<Mat> imageQueue;
    int N = 3; //num images needed to process

    string arg = ("C:user/Desktop//pictures/Sequence/%02d.jpg");
    VideoCapture sequence(arg);

    if(!sequence.isOpened()) {
        cout << "Failed to open image sequence" << endl;
       return -1;
    }

  for(;;)
  {
    Mat image; // !!! a fresh, *local* Mat instance for each image !!!
    sequence >> image;
    if(image.empty()) {
       cout << "End of sequence" << endl;
       break;
    }
    imageQueue.push_back(image);
    if (imageQueue.size() >= N)
    {
           // process imageQueue[0] - imageQueue[N-1]

           imageQueue.pop_front(); // *forget* oldest image
    }
   }
   return 0;
}

as @sturkmen pointed out before, you're reading all of your images into the same (global) Mat image, so you end up with identical copies of the last image read in your vector.

then, trying to read all files into memory is terribly inefficient, rather use a short fifo for the last N frames, and process on-the-fly:

#include <deque>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    deque<Mat> imageQueue;
imageQueue; // use a deque, not a vector
    int N = 3; //num images needed to process

    string arg = ("C:user/Desktop//pictures/Sequence/%02d.jpg");
("C:/user/Desktop/pictures/Sequence/%02d.jpg");
    VideoCapture sequence(arg);

    if(!sequence.isOpened()) {
        cout << "Failed to open image sequence" << endl;
       return -1;
    }

  for(;;)
  {
    Mat image; // !!! a fresh, *local* Mat instance for each image !!!
    sequence >> image;
    if(image.empty()) {
       cout << "End of sequence" << endl;
       break;
    }
    imageQueue.push_back(image);
    if (imageQueue.size() >= N)
    {
           // process imageQueue[0] - imageQueue[N-1]

           imageQueue.pop_front(); // *forget* oldest image
    }
   }
   return 0;
}