import cv2def 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 dstdef main_shake() :vc=cv2.VideoCapture('sample.mp4')c=1cout= 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 = 5cv2. imshow("dst", frame)video_writer.write (frame )c=c+1cv2.waitKey(1)vc. release ()