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 ()
opencv-python视频处理之视频抖动特效
原创
©著作权归作者所有:来自51CTO博客作者东方佑的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章