Ask Your Question
0

I need to do image sequence after extracting frames.

asked 2016-12-16 23:25:47 -0500

Allison gravatar image

updated 2016-12-17 01:28:13 -0500

berak gravatar image

I need to do image sequencing for each movement.I need to use a loop.For e.g,to recognise one movement I need to have 3 static movement in a row.But only one image is being recognised. Below is my c++ code. How to do it please?

using namespace cv;
using namespace std;


vector<Mat> imageQueue;


int main(int argc, char** argv)
{
  string arg = ("C:user/Desktop//pictures/Sequence/%02d.jpg");
  VideoCapture sequence(arg);

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

  Mat image;
  for(;;)
  {
    sequence >> image;
    if(image.empty()) {
       cout << "End of sequence" << endl;
       break;
    }
    imageQueue.push_back(image);
  }

  for(int i = 0; i < 10; i++)
  {
    //display 10 images
    Mat readImage;
    readImage = imageQueue[i];
    namedWindow("Current Image", CV_WINDOW_AUTOSIZE);
    imshow("Current Image", readImage);
    waitKey(100);
  }


return 0;
}
edit retag flag offensive close merge delete

Comments

1

try imageQueue.push_back(image.clone());

sturkmen gravatar imagesturkmen ( 2016-12-17 01:29:48 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-12-17 02:16:50 -0500

berak gravatar image

updated 2016-12-18 02:16:31 -0500

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; // use a deque, not a vector
    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;
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-12-16 23:25:47 -0500

Seen: 131 times

Last updated: Dec 18 '16