Skip to content

Instantly share code, notes, and snippets.

@wermarter
Created January 22, 2017 09:22
Show Gist options
  • Save wermarter/b4c9d7800aefbae30bec01575b68e253 to your computer and use it in GitHub Desktop.
Save wermarter/b4c9d7800aefbae30bec01575b68e253 to your computer and use it in GitHub Desktop.
Transitional Fade Effect
import cv2, time, sys
from random import *
import numpy as np
def trans_effect(named, img1, img2, speed=100):
h1, w1, c1 = img1.shape
h2, w2, c2 = img2.shape
h, w, c = min(h1, h2), min(w1, w2), min(c1, c2)
img1 = img1[:h, :w, :c]
img2 = img2[:h, :w, :c]
for i in range(1, 10):
cv2.imshow(named, cv2.addWeighted(img1, 1-i/10, img2, i/10, 0))
if cv2.waitKey(speed) & 0xFF == ord('q'):
return 'q'
img2 = cv2.imread('me.jpg', -1)
img1 = cv2.imread('me.png', -1)
while 1:
img1, img2 = img2, img1
if trans_effect('img', img1, img2) == 'q':
break
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment