I am using cv2 for Python. I am pretty close to creating a "blending fade" transition between two images, but im not getting the results I hope for.
What I want to do is as my fadein variable counts up, i am passing it to the cv2.addWeighted function to create a blend that changes as my fadein variable changes.
so, summed up...a cinema cross fade effect. Whats happening is the fadein variable counts, and when it reaches its max range, the image jumps to the next one.
[EDIT]
my problem is the cv objects are not simultaneously running with my dynamic fadein variable.
def fadeIn (img1, img2): #pass images here to fade between
while True:
for FADEIN in range(0,10):
fadein = FADEIN/10.0
fadeout=1.0
fadeout -= 0.1
dst = cv2.addWeighted( img1, fadeout, img2, fadein, -1)#linear $
cv2.imshow('window', dst)
print fadein
time.sleep(0.05);
if fadein == 1.0: #blendmode mover
fadein = 1.0
return # exit function
while True:
if Position == 55:
fadeIn(dog, panda)
Your code is also missing the inverse (1-fadein) for the cross fade. I also added a dynamic length setting.
def fadeIn (img1, img2, len=10): #pass images here to fade between
while True:
for IN in range(0,len):
fadein = IN/float(len)
dst = cv2.addWeighted( img1, 1-fadein, img2, fadein, 0)
cv2.imshow('window', dst)
cv2.waitKey(1)
print fadein
Ah, I was missing cv2.waitKey(1)
My revised 'blending' transition between images function:
def fadeIn (img1, img2): #pass images here to fade between
#while True:
for IN in range(0,10):
fadein = IN/10.0
dst = cv2.addWeighted( img1, fadein, img2, fadein, 0)#linear $
cv2.imshow('window', dst)
cv2.waitKey(1)
print fadein
time.sleep(0.05)
if fadein == 1.0: #blendmode mover
fadein = 1.0
return # exit function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With