Using OpenCv and python I'm taking two videos and showing them at the same time on top of each other, semi-transparent.
My issue is that the videos are playing back too slow. The videos are lagging.
Is the code that is calculating the transparency the point that is making the code too slow?
What can I do to speed it up?
Code:
import cv2 as cv
import numpy as np
video = cv.VideoCapture('photos/1.mp4')
video2 = cv.VideoCapture('photos/2.mp4')
while True:
ret, frame = video.read()
ret2, frame2 = video2.read()
# loop videos
if not ret:
print('no video')
video.set(cv.CAP_PROP_POS_FRAMES, 0)
continue
if not ret2:
print('no video')
video2.set(cv.CAP_PROP_POS_FRAMES, 0)
continue
# Blend the two images and show the result
tr = 0.5 # transparency between 0-1, show camera if 0
frame_trans = ((1 - tr) * frame.astype(float) + tr * frame2.astype(float)).astype(np.uint8)
cv.imshow('Transparent result', frame_trans)
if cv.waitKey(1) == ord('d'):
break
video.release()
video2.release()
cv.destroyAllWindows()