Skip to content

Instantly share code, notes, and snippets.

@petrblahos
petrblahos / closedshapes.py
Created January 14, 2018 09:45
Shape interpolation using whole contours, as described in http://petr.blahos.com/blog/shape-warping-03/
import cv2
import numpy as np
import scipy.spatial.distance as distance
def get_interpolated_points(c1, c2, step, scale):
c1 = c1.reshape(c1.shape[0], c1.shape[-1])
c2 = c2.reshape(c2.shape[0], c2.shape[-1])
dif = c2 - c1
return np.array(c1 + dif*step/scale, dtype=np.int32)
@petrblahos
petrblahos / multilines_simple.py
Created January 5, 2018 14:56
Another shape interpolation, as described in http://petr.blahos.com/blog/shape-warping-02/
import cv2
import numpy as np
def get_interpolated_points(c1, c2, step, scale):
dif = c2 - c1
return np.array(c1 + dif*step/scale, dtype=np.int32)
def get_line_list(img, height, simplified):
#anim {
width: 800px;
height: 800px;
}
@petrblahos
petrblahos / warp_letter.py
Created December 20, 2017 10:05
Shape interpolation, as described in http://petr.blahos.com/blog/shape-warping/
import cv2
import numpy as np
import scipy.spatial.distance as distance
def get_interpolated_points(c1, c2, step, scale):
"""
Performs a linear interpolation between c1 and c2. Draws a line between
members of c1 and c2 on the same index, divides the line between the
points into "scale" sections and returns the step-th point.
@petrblahos
petrblahos / ghost_effect.py
Created December 1, 2017 19:35
A python script that generates a video with a "ghost" effect, like this one: https://www.youtube.com/watch?v=Op3OuOc-9CY
import os.path
import cv2
import numpy as np
import pafy
class AddressableQueue(object):
"""
Creates a data structure that will hold some number of records.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
# Copyright 2012 Google, Inc.
# Copyright 2014 Thomas Amland
# Copyright 2015 Petr Blahos
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""
def make_text_table(row_count, column_width):
print "+",
for width in range(5):
print "-",
for width in range(2):
print "+",
for width in range(column_width):
print "-",
print "+"
'''
@petrblahos
petrblahos / tab_petr_ver1.py
Created March 29, 2014 18:46
Textual table
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""