Thursday, 11 March 2021

opencv 10 overlap images


overlapped frame, 50% transparency of both images


#main.py
import numpy as np
import cv2

cap = cv2.VideoCapture("assets/Santa Barbara.mp4")
beach = cv2.imread("assets/beach.jpg")

while True:
    ret, frame = cap.read()
    width = int(cap.get(3))
    height = int(cap.get(4))

    #both images need to be same size
    beach_resized = cv2.resize(beach, (width, height))

    #overlap images (img1, transparency, img2, transparency, offset)
    overlap_frames = cv2.addWeighted(frame, 0.5, beach_resized, 0.5, 0)

    cv2.imshow('frame', overlap_frames)

    if cv2.waitKey(1) == ord('q'):
        break

    if cv2.waitKey(1) == ord('p'):
        # wait until any key is pressed
        cv2.waitKey(-1)

cap.release()
cv2.destroyAllWindows()

reference:

No comments:

Post a Comment