Primitive

Primitive is a command line tool to turn pictures into abstract images.

I played around with it using the frames of this video of a dog in the russian forest:

Primitive time!

How do we get here?

I will start by saving every the frames from an input video to a scaled down png sequence, at 15 fps:

ffmpeg -i video.mov  -r 15 -vf scale=192:108  frames/%04d.png

Now we can run primitive on every frame in the directory, and export the video file:

#!/bin/bash

# use primitive on all images in a directory
cd frames/
arr=(*)
arraylength=${#arr[@]}
workend=$(($arraylength))
for ((i=0; i<$workend; i++)); do
    echo "saving ${arr[$i]}"
    primitive -i ${arr[$i]} -o ../primitive/${arr[$i]} -n 100 -s 1920 -m 1 
done
cd ..


# create mp4 
cd primitive/
ffmpeg -r 15  -start_number 0 -i %04d.png -c:v libx264 -preset medium -b:v 6000k -vf "fps=15,format=yuv420p" -y ../video.mp4

This result is quite shaky despite a steady subject.
We can try to counteract it by blending some nearby frames together:

Here is the script (ImageMagick is used):

#!/bin/bash

# blend 5 images together, to the last-5 one
cd primitive/
arr=(*)
arraylength=${#arr[@]}
workend=$(($arraylength-5))
for ((i=0; i<$workend; i++)); do
    echo "saving ${arr[$i]}"
    convert ${arr[@]:$i:5} -evaluate-sequence mean  ../blended/${arr[$i]}

done
cd ..


# create mp4 
cd blended/
ffmpeg -r 15  -start_number 0 -i %04d.png -c:v libx264 -preset medium -b:v 6000k -vf "fps=15,format=yuv420p" -y ../video.mp4

If you like the jittery feel, try to reduce the number of shapes primitive uses. Here a video with -n 15 istead of 150.

Now if we use the blending technique on this, we get some really nice low polygon effects.

Bonus: primitive does not see not seem to have a very flattering effect on humans:

UPDATE:
On a hunch I tried out using larger shapes on lighter image parts and smaller shapes on darker parts. Just by creating two sets of images with low and high amount of shapes in two folder: primitive and primitivelow, and then combining them with imagemagick using -compose Darken:

The code for reference:

#!/bin/bash

cd primitivelow/
arr=(*)
arraylength=${#arr[@]}
for ((i=0; i<$arraylength; i++)); do
    echo "saving ${arr[$i]}"
    convert ${arr[$i]}  ../primitive/${arr[$i]}   -compose Darken -composite ../darken/${arr[$i]} 
done
cd ..

# create mp4 
cd darken/
ffmpeg -r 15  -start_number 0 -i %04d.png -c:v libx264 -preset medium -b:v 6000k -vf "fps=15,format=yuv420p" -y ../darken.mp4