Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.12 KB

634-1189962-图像的权重.sy.md

File metadata and controls

58 lines (41 loc) · 1.12 KB
import cv2
import imageio
import numpy as np
import time

frame_num = 0
video = cv2.VideoCapture("/mnt/cgshare/xiaoxiongmao.mp4")
image_list = []

width = height = 300
x = y = 150
r = 0
isBigger = True

while True:
    frame_num += 1

    retval, image = video.read()

    if frame_num <= 200:
        continue

    if retval == True:
        cv2.putText(image, "frame: " + str(frame_num), (30, 80), cv2.FONT_HERSHEY_DUPLEX, 2, (65, 90, 120), 5)

    if r == 100:
        isBigger = False
    if r == 10:
        isBigger = True
    if isBigger == True:
        r = r + 1
    else:
        r = r - 1
    animation_img = np.ones((width, height, 3), np.uint8) * 255
    cv2.circle(animation_img, (x, y), r, (65, 89, 120), -1)

    image = cv2.resize(image, (width, height))

    combined_img = cv2.addWeighted(image, 0.7, animation_img, 0.3, 0)

    cv2.imshow("Video", combined_img)

    image_list.append(combined_img)


    key = cv2.waitKey(1)

    if key == 27 or frame_num >= 300:
        break

    time.sleep(1 / 24)

video.release()
cv2.destroyAllWindows()
imageio.mimsave("./xiaoxiongmao_with_animation.gif", image_list, fps=24)