process 10's of thousands of images sequentially

edited November 2017 in How To...

I want to manipulate the sequential frames of a movie , ripped (ffmpeg) into a pile of jpegs and then (ffmpeg) reassemble the movie. I have prototyped the image processing bit in P3 but the code takes so long to run over each frame (1080p HD) that the resulting action is jerky. [basically I track an object as it moves and paint a tail that follows the path taken, not a problem] So thinking to process one frame at a time ... Top level question, can I move the meat of my prototype's draw() functionality into the setup() section and call loadImage() and image() to grab the pixels for analysis within a loop. I am thinking I should dispose the images for gc() continuously too. Secondary question: is it still a requirement that the images must be found in the sketch's data directory ? Has anybody done this sort of thing b4 with P3?

Answers

  • Answer ✓

    loadImage can take a full path rather than just a filename, so the images can be anywhere, not just in data.

    setup() should be fine. try it. in fact, if you put all the processing into a method then you can call that from setup() and if that doesn't work just move the call to draw() (and remember noLoop()).

    you might run into memory issues, even with gc. this was a long-standing bug, some image buffer not being freed up, but i can't remember whether they've fixed it.

  • yeah, must say that for video's I have found the full path capability very helpful. When you change the change the name of the sketch [ rudimentary change management ;) ] not having to copy the data areas around is a boon.

  • but further to @koogs suggestion (doing the work in setup()), now my question is can I get the canvas to display before setup is finished so I can monitor progress ? As it stands I just get to see the last image loaded before setup() finishes.

  • Then don't put them in setup!

    Screen only updates at the end of draw (and setup by the sound of things). But you can use draw, do 100 per frame or whatever.

  • edited December 2017 Answer ✓

    Here is one example modeling how to do things in batches. Here the program exits when the batch jobs are done, but you could just as easily have the program change a flag and move on to another phase of processing.

    /**
     * DoThingsInBatches
     * Jeremy Douglass 2017-12-02 Processing 3.3.6
     **/
    int batchSize=100;
    int counter=0;
    String[] things;
    
    void setup(){
      // create 1000 strings of numbers
      things = new String[1000];
      for(int i=0; i<things.length; i++){
        things[i] = str(i);
      }
      frameRate(1);
    }
    
    void draw(){
      // process a group of them, and update the counter
      counter = doThings(things, batchSize, counter);
      if (counter >= things.length) exit();
    }
    
    // takes a list of things, an amount to process, and a starting position
    int doThings(String[] list, int amt, int oldcount){
      int count=oldcount;
      String output = "";
      while(count<list.length && count < oldcount+amt){
        output = output + list[count] + ' ';
        count++;
      }
      println(output + '\n');
      return count;
    }
    
Sign In or Register to comment.