zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

PythonOpencv 处理 视频 特效 抖动
2023-09-14 09:14:34 时间
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 ()