sampleImage script - how to improve
For scripting exercise I wrote a script that finds all consecutive frames that have the same color, pushes its frame numbers in array called "match", and then extracts only first and last frame of each group of consecutive frames in array called "markers".
( Example: array match = 3,4,5,6,12,13,14,15,16,25,26,27,28; array markers = 3,6,12,16,25,28 )
In the end, the script adds markers on each frame in markers array. I used sampleImage expression which I add to text layer via script, use expression output (through text source) and continue working with values saved in array. For every frame I use 5 points scatered around frame to check for RGB values and if they all match, script pushes frame number to array.
Script works fine, but I'm wondering if there is more elegant way to solve this problem. Are the arrays the way to go? Also, it would be nice if I could rewrite some code to make script faster. I notice that script execution is slower the more sampling points I add (more text layers infused with samplePoint expression). Or maybe the process of comparsion takes longer with more points.
Anyway, if you have advice on better solution I'd be grateful.
Here is the code:
*** I notice some problems with < and > operators when pasting code. Check for loops before running. ***