Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make a video of polygonization of a picture from less polygons to more
#! /usr/bin/python3
from wallgen import *
import os
from PIL import Image
import numpy as np
import cv2
import sys
if len(sys.argv) < 1:
print("Needs file path ")
sys.exit(1)
fn = sys.argv[1]
if not os.path.exists(fn):
print("Invalid path")
sys.exit(1)
ERASE_LINE = '\x1b[2K'
CURSOR_UP_ONE = '\x1b[1A'
img = Image.open(fn)
width = img.width
height = img.height
wshift = img.width//10
hshift = img.height//10
width += wshift*2
height += hshift*2
pts = []
print("Starting ... ")
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('vid.avi', fourcc, 30, (img.width, img.height))
k = 100
for i in range(300):
p = genPoints(k, width, height)
print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE)
print(k, i)
k+=100
pimg = genPoly(img.width, img.height, img, p, wshift, hshift, False, pic=True)
img_np = np.array(pimg)
cimg = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
cv2.imshow("Wallgen", cimg)
cv2.waitKey(1)
out.write(cimg)
cimg = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
for i in range(30):
out.write(cimg) # last second show the original pic
out.release()
cv2.destroyAllWindows()
@SubhrajitPrusty

This comment has been minimized.

Copy link
Owner Author

@SubhrajitPrusty SubhrajitPrusty commented Nov 14, 2018

Takes about 50 mins for me, so please be patient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment