Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 1.64 KB

File metadata and controls

70 lines (54 loc) · 1.64 KB
Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0661
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在: 
	- 个人网站: `https://oeasy.org` 
	- 蓝桥云课: `https://www.lanqiao.cn/courses/3584` 
	- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial` 
	- Gitee: `https://gitee.com/overmind1980/oeasypython` 
---
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)

  • 本文来自 oeasy Python 系统教程。
  • 想完整、扎实学 Python,
  • 搜索 oeasy 即可。