Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b9359b4

Browse files
committed
提交代码
1 parent dfdca3b commit b9359b4

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

‎xianhuan/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Python技术 公众号文章代码库
1010

1111
## 实例代码
1212

13+
[Python 增强视频画质,就这么做!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/enhancevideo):Python 增强视频画质,就这么做!
14+
1315
[Python美图技术也就几行代码!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/imageenhange):Python美图技术也就几行代码!
1416

1517
[几行代码,实现Python捕获、播放和保存摄像头视频!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/videobase):几行代码,实现Python捕获、播放和保存摄像头视频!
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: 闲欢
5+
"""
6+
7+
import cv2
8+
from PIL import ImageEnhance,Image
9+
import numpy as np
10+
11+
def img_enhance(image, brightness=1, color=1,contrast=1,sharpness=1):
12+
# 亮度增强
13+
enh_bri = ImageEnhance.Brightness(image)
14+
if brightness:
15+
image = enh_bri.enhance(brightness)
16+
17+
# 色度增强
18+
enh_col = ImageEnhance.Color(image)
19+
if color:
20+
image = enh_col.enhance(color)
21+
22+
# 对比度增强
23+
enh_con = ImageEnhance.Contrast(image)
24+
if contrast:
25+
image = enh_con.enhance(contrast)
26+
27+
# 锐度增强
28+
enh_sha = ImageEnhance.Sharpness(image)
29+
if sharpness:
30+
image = enh_sha.enhance(sharpness)
31+
32+
return image
33+
34+
35+
cap = cv2.VideoCapture('C:\\xxx.mp4')
36+
success, _ = cap.read()
37+
# 分辨率-宽度
38+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
39+
# 分辨率-高度
40+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
41+
# 总帧数
42+
frame_counter = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
43+
video_writer = cv2.VideoWriter('C:\\result.mp4', cv2.VideoWriter_fourcc('M', 'P', '4', 'V'), 15, (width, height), True)
44+
45+
while success:
46+
success, img1 = cap.read()
47+
try:
48+
image = Image.fromarray(np.uint8(img1)) # 转换成PIL可以处理的格式
49+
img_enhanced = img_enhance(image, 2, 2, 2, 3)
50+
video_writer.write(np.asarray(img_enhanced))
51+
if cv2.waitKey(1) & 0xFF == ord('q'):
52+
break
53+
except:
54+
break
55+
56+
57+
cap.release()
58+
video_writer.release()
59+
cv2.destroyAllWindows()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /