Tiny animator for stop-motion

Last Updated or created 2023-10-23

I was working on a RP2040 HID project, but I needed some components I didn’t have … right now .. again ..

So I made something else ..

A tiny animator for stop motion animations using my webcam, python and OpenCV.

For claymotion or lego or whatever.

The program displays your webcam with the previous snapshot overlayed, so you can position everything relative to your previous snapshot.

Difference between two shots.

Press B to take a frame.

Just a proof of concept using a (BAD) webcam. (Don’t look at my hand )

CODE (short but you need OpenCV)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import cv2
from datetime import datetime
# black is just a start empty image ..
img=cv2.imread("black.png");
cap = cv2.VideoCapture(0)
while True:
ret,vid=cap.read()
dim = (800,600)
img1 = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
vid1 = cv2.resize(vid, dim, interpolation = cv2.INTER_AREA)
result=cv2.addWeighted(img1,0.5,vid1,0.5,0)
cv2.imshow('overlay', result)
if(cv2.waitKey(10) & 0xFF == ord('b')):
now = datetime.now()
current_time = now.strftime("%d_%m_%Y_%H_%M_%S")
filename = '%s.png' % current_time
if not cv2.imwrite(filename, vid1):
raise Exception("Could not write image")
img=cv2.imread(filename);
import cv2 from datetime import datetime # black is just a start empty image .. img=cv2.imread("black.png"); cap = cv2.VideoCapture(0) while True: ret,vid=cap.read() dim = (800,600) img1 = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) vid1 = cv2.resize(vid, dim, interpolation = cv2.INTER_AREA) result=cv2.addWeighted(img1,0.5,vid1,0.5,0) cv2.imshow('overlay', result) if(cv2.waitKey(10) & 0xFF == ord('b')): now = datetime.now() current_time = now.strftime("%d_%m_%Y_%H_%M_%S") filename = '%s.png' % current_time if not cv2.imwrite(filename, vid1): raise Exception("Could not write image") img=cv2.imread(filename);
import  cv2
from datetime import datetime
# black is just a start empty image .. 
img=cv2.imread("black.png");
cap = cv2.VideoCapture(0)

while True: 

    ret,vid=cap.read()
    dim = (800,600)
    img1 = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
    vid1 = cv2.resize(vid, dim, interpolation = cv2.INTER_AREA)

    result=cv2.addWeighted(img1,0.5,vid1,0.5,0)
    cv2.imshow('overlay', result)
    if(cv2.waitKey(10) & 0xFF == ord('b')):
            now = datetime.now()
            current_time = now.strftime("%d_%m_%Y_%H_%M_%S")
            filename = '%s.png' % current_time
            if not cv2.imwrite(filename, vid1):
                raise Exception("Could not write image")
            img=cv2.imread(filename);

Pressing B fills your directory with PNG’s
like 24_10_2023_00_01_01.png (date formatted)

convert to GIF

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
convert -delay 10 -loop 0 24*.png animation.gif
convert -delay 10 -loop 0 24*.png animation.gif
convert -delay 10 -loop 0 24*.png animation.gif
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *