Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_opencv
提交
ef63ef77
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看板
提交
ef63ef77
编写于
12月 08, 2021
作者:
F
feilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add open+close
上级
4e46ebd6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
188 addition
and
0 deletion
+188
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/bird.png
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/bird.png
+0
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/close.md
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/close.md
+72
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/close.py
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/close.py
+22
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/img_closed.jpeg
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/img_closed.jpeg
+0
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/img_opened.jpeg
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/img_opened.jpeg
+0
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/open.md
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/open.md
+72
-0
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/open.py
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/open.py
+22
-0
未找到文件。
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/bird.png
0 → 100644
浏览文件 @
ef63ef77
2.3 MB
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/close.md
0 → 100644
浏览文件 @
ef63ef77
# 小鸊鷉橡皮擦(II)
OpenCV 里先膨胀再腐蚀操作叫做“闭运算”。小鸊鷉(pi ti)的名片被小朋友画了几笔,尝试通过先腐蚀再膨胀修复,完成任务
![](
./img_closed.jpeg
)
框架代码如下:
```
python
import
numpy
as
np
import
cv2
def
close_op
(
img
):
# TODO(You): 请在此实现代码
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'bird.png'
,
cv2
.
COLOR_BGR2LAB
)
img_opened
=
open_op
(
img_origin
)
img_all
=
np
.
concatenate
((
img_origin
,
img_opened
),
axis
=
1
)
cv2
.
imwrite
(
'img_opened.jpeg'
,
img_all
)
cv2
.
imshow
(
'img: origin, erosion and dilation'
,
img_all
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
```
下面对开运算函数
`def close_op(img):`
实现正确的是?
## 答案
```
python
def
close_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
dilate
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
erode
(
img1
,
kernel
,
iterations
=
1
)
return
img2
```
## 选项
### 都是对原图操作
```
python
def
close_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
dilate
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
erode
(
img
,
kernel
,
iterations
=
1
)
return
img2
```
### 顺序不对
```
python
def
close_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
erode
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
dilate
(
img1
,
kernel
,
iterations
=
1
)
return
img2
```
### 返回错误
```
python
def
close_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
dilate
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
erode
(
img1
,
kernel
,
iterations
=
1
)
return
img1
```
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/close.py
0 → 100644
浏览文件 @
ef63ef77
import
numpy
as
np
import
cv2
def
close_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
dilate
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
erode
(
img1
,
kernel
,
iterations
=
1
)
return
img2
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'bird.png'
,
cv2
.
COLOR_BGR2LAB
)
img_closed
=
close_op
(
img_origin
)
img_all
=
np
.
concatenate
((
img_origin
,
img_closed
),
axis
=
1
)
cv2
.
imwrite
(
'img_closed.jpeg'
,
img_all
)
cv2
.
imshow
(
'img: origin, erosion and dilation'
,
img_all
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/img_closed.jpeg
0 → 100644
浏览文件 @
ef63ef77
91.7 KB
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/img_opened.jpeg
0 → 100644
浏览文件 @
ef63ef77
94.8 KB
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/open.md
0 → 100644
浏览文件 @
ef63ef77
# 小鸊鷉橡皮擦(I)
OpenCV 里先腐蚀再膨胀操作叫做“开运算”。小鸊鷉(pi ti)的名片被小朋友画了几笔,尝试通过先腐蚀再膨胀修复,效果不明显
![](
./img_opened.jpeg
)
框架代码如下:
```
python
import
numpy
as
np
import
cv2
def
open_op
(
img
):
# TODO(You): 请在此实现代码
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'bird.png'
,
cv2
.
COLOR_BGR2LAB
)
img_opened
=
open_op
(
img_origin
)
img_all
=
np
.
concatenate
((
img_origin
,
img_opened
),
axis
=
1
)
cv2
.
imwrite
(
'img_opened.jpeg'
,
img_all
)
cv2
.
imshow
(
'img: origin, erosion and dilation'
,
img_all
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
```
下面对开运算函数
`def open_op(img):`
实现正确的是?
## 答案
```
python
def
open_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
erode
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
dilate
(
img1
,
kernel
,
iterations
=
1
)
return
img2
```
## 选项
### 都是对原图操作
```
python
def
open_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
erode
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
dilate
(
img
,
kernel
,
iterations
=
1
)
return
img2
```
### 顺序不对
```
python
def
open_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
dilate
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
erode
(
img1
,
kernel
,
iterations
=
1
)
return
img2
```
### 返回错误
```
python
def
open_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
erode
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
dilate
(
img1
,
kernel
,
iterations
=
1
)
return
img1
```
data/1.OpenCV初阶/2.二值图像处理/3.开运算与闭运算/open.py
0 → 100644
浏览文件 @
ef63ef77
import
numpy
as
np
import
cv2
def
open_op
(
img
):
kernel
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
img1
=
cv2
.
erode
(
img
,
kernel
,
iterations
=
1
)
img2
=
cv2
.
dilate
(
img1
,
kernel
,
iterations
=
1
)
return
img2
if
__name__
==
'__main__'
:
img_origin
=
cv2
.
imread
(
'bird.png'
,
cv2
.
COLOR_BGR2LAB
)
img_opened
=
open_op
(
img_origin
)
img_all
=
np
.
concatenate
((
img_origin
,
img_opened
),
axis
=
1
)
cv2
.
imwrite
(
'img_opened.jpeg'
,
img_all
)
cv2
.
imshow
(
'img: origin, erosion and dilation'
,
img_all
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录