How to save videograbber.getPixels in variable or vector?

Hello,

I am trying to create a sequence captured from videoGrabber.getPixels()

void update(){
..
unsigned char *pixels = vidGrabber.getPixels();
videoFramesVector.push_back(pixels);
}

void draw (){
		unsigned char *tmp = videoFramesVector[playbackCounter];

		ofImage img;
		ofPixels pix;

		pix.setFromExternalPixels(tmp,640,480,3);

		img.setFromPixels(pix);
        img.draw(20,420);
        playbackCounter++;

}

however, seems like, the pointer is always pointing to the what videoGrabber.getPixels()…
so it didn’t store the pixels in the vector…

Can someone please help… tell me how i can store image sequence pixels getting from videoGrabber?

thanks!

however, seems like, the pointer is always pointing to the what videoGrabber.getPixels()…

You have pretty much hit the nail on the head with this, as this is what your code is doing. What you get from vidGrabber.getPixels() is a pointer that you are storing. What you want to do instead is to store the data pointed to by that pointer. Do something like this in update:

unsigned char *pixels = vidGrabber.getPixels();

//Make a place to store the data. Obviously pixels.size() won't work. You just need to get the number of stored bytes somehow. Maybe a function of vidGrabber can tell you the number of stored bytes?
vector<unsigned char> copyOfPixels(pixels.size());

//Copy the data over.
for (unsigned int i = 0; i < copyOfPixels.size(); i++) {
   copyOfPixels[i] = pixels[i];
}

//videoFramesVector must be changed to be a vector< vector<unsigned char> >, i.e. a vector of vectors.
videoFramesVector.push_back(pixels);
//Note that it would be more efficient to create the copyOfPixels in place within videoFrameVector instead of pushing it here. Pushing causes an additional, unnecessary copy operation.