Skip to content

Commit e67cead

Browse files
committed
提交代码
1 parent 06546e8 commit e67cead

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-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+
[嘿嘿!几行代码秒出美女素描图!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/pencilimg):嘿嘿!几行代码秒出美女素描图!
14+
1315
[几行代码就能实现漂亮进度条,太赞了!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/tqdm):几行代码就能实现漂亮进度条,太赞了!
1416

1517
[用Python来做一个屏幕录制工具](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/videorecord):用Python来做一个屏幕录制工具

xianhuan/pencilimg/pencilImg.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: 闲欢
5+
"""
6+
import cv2
7+
8+
# 读取 RGB 格式的美女图片
9+
img = cv2.imread("mv5.jpg")
10+
# 将 BGR 图像转为灰度模式
11+
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12+
# 显示灰度图像
13+
# cv2.imshow('grey', gray_img)
14+
# cv2.waitKey(0)
15+
# cv2.imwrite("./grey.jpg", gray_img, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
16+
# 反转图像
17+
inverted_img = 255 - gray_img
18+
19+
# 创建铅笔草图
20+
blurred = cv2.GaussianBlur(inverted_img, (21, 21), 0)
21+
inverted_blurred = 255 - blurred
22+
cv2.imwrite("./inverted_blurred.jpg", inverted_blurred, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
23+
pencil_sketch = cv2.divide(gray_img, inverted_blurred, scale=256.0)
24+
# 显示图像
25+
cv2.imshow("original", img)
26+
cv2.imshow("pencil", pencil_sketch)
27+
cv2.waitKey(0)
28+
29+
30+
31+

0 commit comments

Comments
 (0)