import numpy as np from PIL import Image import cv2
# #爆破a,b # im = Image.open('final.jpg') # im = np.array(im)
# def dearnold(img): # r,c,t = img.shape # p = np.zeros((r,c,t),dtype=np.uint8) # for a in range(1, 11): # for b in range(1, 11): # for i in range(r): # for j in range(c): # for k in range(t): # x = ((a*b+1)*i - b*j)%r # y = (-a*i + j)%r # p[x,y,k] = img[i,j,k] # filename = f'./dearnold{a}_{b}.jpg' # cv2.imwrite(filename, p) # print('dearnold{}_{}'.format(a, b)) # return p # #dearnold(im) # ##直接看图片dearnold5_5为正常图片=>得到a=5, b=5
defvideo_dearnold(img): r,c,t = img.shape p = np.zeros((r,c,t),dtype=np.uint8) a = 5 b = 5 for i inrange(r): for j inrange(c): for k inrange(t): x = ((a*b+1)*i - b*j)%r y = (-a*i + j)%r p[x,y,k] = img[i,j,k] return p defvideo(input_video,output_video): #打开视频 cap = cv2.VideoCapture(input_video) #获取宽、高、帧率 width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = int(cap.get(cv2.CAP_PROP_FPS)) # 设置输出视频的编码器和参数 fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter(output_video, fourcc, fps, (width, height), isColor=True)
while cap.isOpened(): ret, frame = cap.read() if ret: frame = video_dearnold(frame)`` out.write(frame) else: break cap.release() out.release()