Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_opencv
提交
b4697401
S
skill_tree_opencv
项目概览
CSDN 技术社区
/
skill_tree_opencv
通知
65
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看板
提交
b4697401
编写于
12月 13, 2021
作者:
F
feilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加单应性变换
上级
6dcaa47d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
143 addition
and
0 deletion
+143
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face.md
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face.md
+115
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face.py
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face.py
+28
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_dest.jpeg
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_dest.jpeg
+0
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_homography.jpeg
.../1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_homography.jpeg
+0
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_origin.jpeg
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_origin.jpeg
+0
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_rule.jpg
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_rule.jpg
+0
-0
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_src.jpeg
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_src.jpeg
+0
-0
未找到文件。
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face.md
0 → 100644
浏览文件 @
b4697401
# 还原挤地铁的参赛作品
下图左边的参赛作品(图片来自网络)掉到地上,重新做太麻烦了,据说改了个《挤地铁》的名字获奖了。
![](
./rust_face_origin.jpeg
)
我们可以通过 OpenCV 单应性变换的方式帮助挤地铁的人脸还原。
把没挤扁和挤扁的图的坐标标注出来
![](
./rust_face_rule.jpg
)
可以看到还原后的侧脸
![](
./rust_face_homography.jpeg
)
以下正确的实现是
## 答案
```
python
import
cv2
import
numpy
as
np
if
__name__
==
'__main__'
:
img_src
=
cv2
.
imread
(
'rust_face_src.jpeg'
)
pts_src
=
np
.
array
([[
0
,
0
],
[
570
,
0
],
[
570
,
1078
],
[
0
,
1078
]])
img_dst
=
cv2
.
imread
(
'rust_face_dest.jpeg'
)
pts_dst
=
np
.
array
([[
63
,
285
],
[
378
,
224
],
[
427
,
689
],
[
84
,
820
]])
dw
,
dh
=
img_dst
.
shape
[
1
],
img_dst
.
shape
[
0
]
h
,
status
=
cv2
.
findHomography
(
pts_src
,
pts_dst
)
img_out
=
cv2
.
warpPerspective
(
img_src
,
h
,
(
dw
,
dh
))
images
=
np
.
concatenate
((
img_src
[
0
:
dh
,
0
:
dw
,
0
:
3
],
img_dst
,
img_out
),
axis
=
1
)
cv2
.
imshow
(
'homography'
,
images
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
```
## 选项
### 映射位置不匹配
```
python
import
cv2
import
numpy
as
np
if
__name__
==
'__main__'
:
img_src
=
cv2
.
imread
(
'rust_face_src.jpeg'
)
pts_src
=
np
.
array
([[
0
,
0
],
[
0
,
1078
],
[
570
,
0
],
[
570
,
1078
]])
img_dst
=
cv2
.
imread
(
'rust_face_dest.jpeg'
)
pts_dst
=
np
.
array
([[
63
,
285
],
[
378
,
224
],
[
427
,
689
],
[
84
,
820
]])
dw
,
dh
=
img_dst
.
shape
[
1
],
img_dst
.
shape
[
0
]
h
,
status
=
cv2
.
findHomography
(
pts_src
,
pts_dst
)
img_out
=
cv2
.
warpPerspective
(
img_src
,
h
,
(
dw
,
dh
))
images
=
np
.
concatenate
((
img_src
[
0
:
dh
,
0
:
dw
,
0
:
3
],
img_dst
,
img_out
),
axis
=
1
)
cv2
.
imshow
(
'homography'
,
images
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
```
### 源图和目标图片错位
```
python
import
cv2
import
numpy
as
np
if
__name__
==
'__main__'
:
img_src
=
cv2
.
imread
(
'rust_face_src.jpeg'
)
pts_src
=
np
.
array
([[
0
,
0
],
[
0
,
1078
],
[
570
,
0
],
[
570
,
1078
]])
img_dst
=
cv2
.
imread
(
'rust_face_dest.jpeg'
)
pts_dst
=
np
.
array
([[
63
,
285
],
[
378
,
224
],
[
427
,
689
],
[
84
,
820
]])
dw
,
dh
=
img_dst
.
shape
[
1
],
img_dst
.
shape
[
0
]
h
,
status
=
cv2
.
findHomography
(
pts_dst
,
pts_src
)
img_out
=
cv2
.
warpPerspective
(
img_src
,
h
,
(
dw
,
dh
))
images
=
np
.
concatenate
((
img_src
[
0
:
dh
,
0
:
dw
,
0
:
3
],
img_dst
,
img_out
),
axis
=
1
)
cv2
.
imshow
(
'homography'
,
images
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
```
### 目标长宽用错
```
python
import
cv2
import
numpy
as
np
if
__name__
==
'__main__'
:
img_src
=
cv2
.
imread
(
'rust_face_src.jpeg'
)
pts_src
=
np
.
array
([[
0
,
0
],
[
0
,
1078
],
[
570
,
0
],
[
570
,
1078
]])
img_dst
=
cv2
.
imread
(
'rust_face_dest.jpeg'
)
pts_dst
=
np
.
array
([[
63
,
285
],
[
378
,
224
],
[
427
,
689
],
[
84
,
820
]])
dw
,
dh
=
img_dst
.
shape
[
1
],
img_dst
.
shape
[
0
]
h
,
status
=
cv2
.
findHomography
(
pts_dst
,
pts_src
)
img_out
=
cv2
.
warpPerspective
(
img_src
,
h
,
(
dh
,
dw
))
images
=
np
.
concatenate
((
img_src
[
0
:
dh
,
0
:
dw
,
0
:
3
],
img_dst
,
img_out
),
axis
=
1
)
cv2
.
imshow
(
'homography'
,
images
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
```
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face.py
0 → 100644
浏览文件 @
b4697401
import
cv2
import
numpy
as
np
import
matplotlib.pyplot
as
plt
if
__name__
==
'__main__'
:
# img_src = cv2.imread('rust_face_src.jpeg')
# pts_src = np.array([[0, 0], [570, 0], [570, 1078], [0, 1078]])
# img_dst = cv2.imread('rust_face_dest.jpeg')
# pts_dst = np.array([[63, 285], [378, 224], [427, 689], [84, 820]])
img_src
=
cv2
.
imread
(
'rust_face_src.jpeg'
)
pts_src
=
np
.
array
([[
0
,
0
],
[
0
,
1078
],
[
570
,
0
],
[
570
,
1078
]])
img_dst
=
cv2
.
imread
(
'rust_face_dest.jpeg'
)
pts_dst
=
np
.
array
([[
63
,
285
],
[
84
,
820
],
[
378
,
224
],
[
427
,
689
]])
dw
,
dh
=
img_dst
.
shape
[
1
],
img_dst
.
shape
[
0
]
h
,
status
=
cv2
.
findHomography
(
pts_src
,
pts_dst
)
img_out
=
cv2
.
warpPerspective
(
img_src
,
h
,
(
dw
,
dh
))
images
=
np
.
concatenate
(
(
img_src
[
0
:
dh
,
0
:
dw
,
0
:
3
],
img_dst
,
img_out
),
axis
=
1
)
cv2
.
imshow
(
'homography'
,
images
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_dest.jpeg
0 → 100644
浏览文件 @
b4697401
92.8 KB
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_homography.jpeg
0 → 100644
浏览文件 @
b4697401
289.8 KB
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_origin.jpeg
0 → 100644
浏览文件 @
b4697401
73.4 KB
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_rule.jpg
0 → 100644
浏览文件 @
b4697401
81.2 KB
data/1.OpenCV初阶/4.几何变换和图像特征/2.单应性变换/rust_face_src.jpeg
0 → 100644
浏览文件 @
b4697401
93.4 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录