有一段很多年前的太极拳教学演示视频,在大屏幕电视播放,视频画面实在让人看不下去,就想有什么办法提高视频画质,安装Topaz Video Enhance AI软件可以实现,但我还是喜欢自己折腾python,直接记录折腾笔记。
安装pillow和opencv-python
1 2 3 4
| pip3 install opencv-python pip3 install pillow
|
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| import cv2 from PIL import ImageEnhance, Image import numpy as np cap = cv2.VideoCapture('/Users/mymac/Movies/太极拳/24式整套 .mp4') images = [] def img\_enhance(image):
enh\_bri = ImageEnhance.Brightness(image) brightness = 1.2 image\_brightened = enh\_bri.enhance(brightness)
enh\_col = ImageEnhance.Color(image\_brightened) color = 1.2 image\_colored = enh\_col.enhance(color)
enh\_con = ImageEnhance.Contrast(image\_colored) contrast = 1.2 image\_contrasted = enh\_con.enhance(contrast)
enh\_sha = ImageEnhance.Sharpness(image\_contrasted) sharpness = 1.2 image\_sharped = enh\_sha.enhance(sharpness)
return image\_sharped while (cap.isOpened()): ret, frame = cap.read()
image = Image.fromarray(np.uint8(frame))
images.append(image) cv2.imshow('frame', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break
image\_enhanced = img\_enhance(image)
cv2.imshow('frame\_enhanced', np.asarray(image\_enhanced))
if cv2.waitKey(25) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
|