Last active
November 14, 2018 19:05
-
-
Save SubhrajitPrusty/37cf527ca4d92ed4a19af91099984b51 to your computer and use it in GitHub Desktop.
Make a video of polygonization of a picture from less polygons to more
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Takes about 50 mins for me, so please be patient.