逐帧P视频水印

逐帧P视频水印,第1张

1.实现功能:

(1)读取本地视频

(2)逐帧鼠标左键框选水印部分,覆盖为白色

(3)按按键‘y’,'Y'使用上一次位置的框覆盖此次的水印

(4)按其他按键表示不处理当前帧

2.调库
import cv2
import numpy as np
import easygui
import copy
 3.完整源码
import cv2
import numpy as np
import easygui
import copy

global frame, point1, point2, key
key = False
point1 = point2 = (0,0)

videopath = easygui.fileopenbox()
cap = cv2.VideoCapture(videopath)
if not cap.isOpened():
    easygui.msgbox("video read failure")
    exit(0)

video_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
video_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))

cv2.namedWindow('result')

def Rectangular_box(event, x, y, flags, param):
    global frame, point1, point2
    img = frame.copy()
    if event == cv2.EVENT_LBUTTONDOWN:
        point1 = (x, y)
        cv2.circle(img, point1, 10, (0, 255, 0), 5)
        cv2.imshow('result', img)
    elif event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_LBUTTON):
        cv2.rectangle(img, point1, (x, y), (255, 0, 0), 5)
        cv2.imshow('result', img)
    elif event == cv2.EVENT_LBUTTONUP:
        point2 = (x, y)
        cv2.rectangle(img, point1, point2, (0, 255, 255), 4)

        mask = np.zeros([video_height,video_width,3],np.uint8)
        max_h = point1[1] if point1[1]>point2[1] else point2[1]
        min_h = point1[1] if point1[1]point2[0] else point2[0]
        min_w = point1[0] if point1[0]point2[1] else point2[1]
        min_h = point1[1] if point1[1]point2[0] else point2[0]
        min_w = point1[0] if point1[0]
4.未完成

保存视频

5.参考文章

(1条消息) opencv进阶学习笔记6:使用鼠标在图像上绘制矩形框或者多边形框_总裁余(余登武)的博客-CSDN博客_opencv鼠标绘制多边形https://blog.csdn.net/kobeyu652453/article/details/107309456EasyGUI 学习文档【超详细中文版】(from小甲鱼 ) - 廖海清 - 博客园 (cnblogs.com)https://www.cnblogs.com/hale547/p/13301951.html

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/739430.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)