cannot store video feed to image array
in
Core Library Questions
•
1 year ago
This is inspired by openframeworks code shared by James George.
I am basically trying to save frames from a video feed into an image array, and then choose how that image array will be shown.
I can get it to work, almost, but it seems that the images which I am saving are all turning out the same. I can do the same thing with opencv, but it hiccups and does not work very well.
Here is the gist of the code:
- import processing.video.*;
- Capture video;
- int frameNumber = 0; //start at frame 1
- int fBM = 60; //fBM = frameBufferMaximum
- PImage img;
- PImage[] frameBuffer = new PImage[fBM+1]; //store 60 frames
- void setup() {
- size(800, 480, P2D);
- // Uses the default video input, see the reference if this causes an error
- video = new Capture(this, 640, 480);
- video.start();
- background(0);
- img = createImage(video.width,video.height,RGB);
- //prepare the image array
- for (int i=0;i<fBM;i++){
- frameBuffer[frameNumber]=createImage(video.width,video.height,RGB);
- }
- }
- void draw() {
- if (video.available()) {
- video.read();
- video.loadPixels();
- //copy the video frame
- img.copy(video,0,0,video.width,video.height,0,0,video.width,video.height);
- //store the video frame
- frameBuffer[frameNumber]=img;
- frameBuffer[frameNumber].updatePixels();
- frameNumber ++;
- if (frameNumber > fBM) {
- for (int i=0;i<fBM-1;i++){
- //push frames down the array
- frameBuffer[i]=frameBuffer[i+1];
- frameNumber = fBM;
- }
- }
- }
- //draw the images on screen
- for (int i=frameNumber;i>0-1;i--){
- if((frameBuffer[i] != null)){
- image(frameBuffer[i],width-2*i,0,100,height);
- }
- }
- }
This should be fairly straight forward, but it seems all of the images are the same, current frame of video being shown. It should be generating a relative video delay with this process, but it doesn't work that way.
I've searched several forums, but cannot figure out how to get a video frame to be copied as an image for later use. It's very perplexing. Any help would be appreciated.
1