Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_opencv
提交
425383fa
S
skill_tree_opencv
项目概览
CSDN 技术社区
/
skill_tree_opencv
通知
57
Star
9
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
425383fa
编写于
12月 06, 2021
作者:
F
feilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add hack
上级
d3bd1d1d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
239 addition
and
1 deletion
+239
-1
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/config.json
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/config.json
+3
-1
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.jpg
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.jpg
+0
-0
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.json
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.json
+0
-0
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.md
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.md
+169
-0
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.py
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.py
+67
-0
未找到文件。
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/config.json
浏览文件 @
425383fa
...
...
@@ -5,6 +5,7 @@
],
"children"
:
[],
"export"
:
[
"pixel.json"
"pixel.json"
,
"hack.json"
]
}
\ No newline at end of file
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.jpg
0 → 100644
浏览文件 @
425383fa
66.9 KB
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.json
0 → 100644
浏览文件 @
425383fa
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.md
0 → 100644
浏览文件 @
425383fa
# 图片黑客帝国化
黑客帝国的图片风格偏绿色,任意图片的每个像素(r,g,b)经过公式转换后即可获得一张“黑客帝国风格图片”:
*
r = r
<sup>
3/2
</sup>
*
g = r
<sup>
4/5
</sup>
*
b = r
<sup>
3/2
</sup>
我们对
`lena`
图片也做黑客帝国风格化处理:
```
python
import
numpy
as
np
import
cv2
import
math
def
hacker
(
img
):
# TODO(You): 请在此添加代码
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'lena.png'
,
cv2
.
IMREAD_COLOR
)
img
=
cv2
.
imread
(
'lena.png'
,
cv2
.
IMREAD_COLOR
)
print
(
img
.
size
)
print
(
img
.
shape
)
hacker
(
img
)
print
(
'显示图片,请按任意键退出'
)
numpy_horizontal_concat
=
np
.
concatenate
((
img_origin
,
img
),
axis
=
1
)
cv2
.
imshow
(
'Lena图片黑客帝国化'
,
numpy_horizontal_concat
)
cv2
.
waitKey
()
cv2
.
destroyAllWindows
()
```
以下选项是对函数
`def hacker(img)`
的实现,请选出
<span
style=
"color:red"
>
实现有错
</span>
的选项。
## template
```
python
import
numpy
as
np
import
cv2
import
math
def
hacker_1
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
.
item
((
i
,
j
,
0
)),
img
.
item
(
(
i
,
j
,
1
)),
img
.
item
((
i
,
j
,
2
))
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
.
itemset
((
i
,
j
,
0
),
hack_b
)
img
.
itemset
((
i
,
j
,
1
),
hack_g
)
img
.
itemset
((
i
,
j
,
2
),
hack_r
)
def
hacker_2
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
[
i
,
j
]
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
[
i
,
j
]
=
(
hack_b
,
hack_g
,
hack_r
)
def
hacker_3
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
.
item
((
i
,
j
))
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
.
itemset
((
i
,
j
),
(
hack_b
,
hack_g
,
hack_r
))
def
hacker
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
[
i
,
j
]
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
[
i
,
j
,
0
]
=
hack_b
img
[
i
,
j
,
1
]
=
hack_g
img
[
i
,
j
,
2
]
=
hack_r
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'lena.png'
,
cv2
.
IMREAD_COLOR
)
img
=
cv2
.
imread
(
'lena.png'
,
cv2
.
IMREAD_COLOR
)
print
(
img
.
size
)
print
(
img
.
shape
)
hacker
(
img
)
print
(
'显示图片,请按任意键退出'
)
numpy_horizontal_concat
=
np
.
concatenate
((
img_origin
,
img
),
axis
=
1
)
cv2
.
imshow
(
'Lena图片黑客帝国化'
,
numpy_horizontal_concat
)
cv2
.
waitKey
()
cv2
.
destroyAllWindows
()
```
## 答案
```
python
def
hacker
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
.
item
((
i
,
j
))
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
.
itemset
((
i
,
j
),
(
hack_b
,
hack_g
,
hack_r
))
```
## 选项
### item+itemset
```
python
def
hacker
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
.
item
((
i
,
j
,
0
)),
img
.
item
((
i
,
j
,
1
)),
img
.
item
((
i
,
j
,
2
))
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
.
itemset
((
i
,
j
,
0
),
hack_b
)
img
.
itemset
((
i
,
j
,
1
),
hack_g
)
img
.
itemset
((
i
,
j
,
2
),
hack_r
)
```
### 直接读取像素
```
python
def
hacker
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
[
i
,
j
]
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
[
i
,
j
]
=
(
hack_b
,
hack_g
,
hack_r
)
```
### 下标访问到通道
```
python
def
hacker
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
[
i
,
j
]
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
[
i
,
j
,
0
]
=
hack_b
img
[
i
,
j
,
1
]
=
hack_g
img
[
i
,
j
,
2
]
=
hack_r
```
data/1.OpenCV初阶/1.OpenCV基础/3.图像的基本操作/hack.py
0 → 100644
浏览文件 @
425383fa
import
numpy
as
np
import
cv2
import
math
def
hacker_1
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
.
item
((
i
,
j
,
0
)),
img
.
item
(
(
i
,
j
,
1
)),
img
.
item
((
i
,
j
,
2
))
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
.
itemset
((
i
,
j
,
0
),
hack_b
)
img
.
itemset
((
i
,
j
,
1
),
hack_g
)
img
.
itemset
((
i
,
j
,
2
),
hack_r
)
def
hacker_2
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
[
i
,
j
]
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
[
i
,
j
]
=
(
hack_b
,
hack_g
,
hack_r
)
def
hacker_3
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
.
item
((
i
,
j
))
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
.
itemset
((
i
,
j
),
(
hack_b
,
hack_g
,
hack_r
))
def
hacker
(
img
):
height
,
width
,
channels
=
img
.
shape
for
i
in
range
(
0
,
width
):
for
j
in
range
(
0
,
height
):
b
,
g
,
r
=
img
[
i
,
j
]
hack_b
=
int
(
math
.
pow
(
b
/
256.0
,
3
/
2
)
*
256
)
hack_g
=
int
(
math
.
pow
(
g
/
256.0
,
4
/
5
)
*
256
)
hack_r
=
int
(
math
.
pow
(
r
/
256.0
,
3
/
2
)
*
256
)
img
[
i
,
j
,
0
]
=
hack_b
img
[
i
,
j
,
1
]
=
hack_g
img
[
i
,
j
,
2
]
=
hack_r
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'lena.png'
,
cv2
.
IMREAD_COLOR
)
img
=
cv2
.
imread
(
'lena.png'
,
cv2
.
IMREAD_COLOR
)
print
(
img
.
size
)
print
(
img
.
shape
)
hacker
(
img
)
print
(
'显示图片,请按任意键退出'
)
numpy_horizontal_concat
=
np
.
concatenate
((
img_origin
,
img
),
axis
=
1
)
cv2
.
imshow
(
'Lena图片黑客帝国化'
,
numpy_horizontal_concat
)
cv2
.
waitKey
()
cv2
.
destroyAllWindows
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录