当前位置: 移动技术网 > IT编程>脚本编程>Python > opencv-python视频处理之视频抖动特效

opencv-python视频处理之视频抖动特效

2020年07月13日  | 移动技术网IT编程  | 我要评论
import cv2
def img_shake (img) :
    height, width, n= img. shape
    h1=int (height*0.1)
    h2=int (height*0.9)
    wl = int (width*0.1)
    w2 = int (width*0.9)
    img2=img[h1:h2,wl:w2]
    dst = cv2. resize (img2, (width, height) )
    cv2.imshow("src", img)
    cv2.imshow ("dst",dst)
    return dst
def main_shake() :
    vc=cv2.VideoCapture('sample.mp4')
    c=1
    cout= 5#抖动帧数
    fps = vc.get (cv2.CAP_PROP_FPS )
    fourcc = cv2.VideoWriter_fourcc(* 'MJPG')
    video_writer = cv2.VideoWriter("img_shake.mp4", fourcc, fps, (640, 480))
    while vc. isOpened() :
        rval, frame = vc. read ()
        # 每5帧抖动一次
        if(c%5==0or 0<cout<5) :
            dst=img_shake(frame)
            video_writer.write (dst)
        else:
            # 这里可以控制抖动帧数
            cout = 5
            cv2. imshow("dst", frame)
            video_writer.write (frame )
            c=c+1
        cv2.waitKey(1)
    vc. release ()



本文地址:https://blog.csdn.net/weixin_32759777/article/details/107305222

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网