We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
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.
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.