Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenCV
opencv
提交
c982be39
O
opencv
项目概览
OpenCV
/
opencv
上一次同步 8 个月
通知
988
Star
71100
Fork
55581
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
c982be39
编写于
6月 25, 2023
作者:
A
Alexander Smorkalov
提交者:
GitHub
6月 25, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23863 from asmorkalov:as/calibrate_py_rework
Reworked calibrate.py
上级
bf06bc92
85ea247c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
37 deletion
+40
-37
samples/python/calibrate.py
samples/python/calibrate.py
+40
-37
未找到文件。
samples/python/calibrate.py
浏览文件 @
c982be39
...
...
@@ -16,11 +16,13 @@ default values:
-w: 4
-h: 6
-t: chessboard
--square_size:
5
0
--marker_size:
2
5
--square_size:
1
0
--marker_size: 5
--aruco_dict: DICT_4X4_50
--threads: 4
<image mask> defaults to ../data/left*.jpg
NOTE: Chessboard size is defined in inner corners. Charuco board size is defined in units.
'''
# Python 2/3 compatibility
...
...
@@ -67,45 +69,38 @@ def main():
marker_size
=
float
(
args
.
get
(
'--marker_size'
))
aruco_dict_name
=
str
(
args
.
get
(
'--aruco_dict'
))
pattern_size
=
(
height
,
width
)
pattern_size
=
(
width
,
height
)
if
pattern_type
==
'chessboard'
:
pattern_points
=
np
.
zeros
((
np
.
prod
(
pattern_size
),
3
),
np
.
float32
)
pattern_points
[:,
:
2
]
=
np
.
indices
(
pattern_size
).
T
.
reshape
(
-
1
,
2
)
pattern_points
*=
square_size
elif
pattern_type
==
'charucoboard'
:
pattern_points
=
np
.
zeros
((
np
.
prod
((
height
-
1
,
width
-
1
)),
3
),
np
.
float32
)
pattern_points
[:,
:
2
]
=
np
.
indices
((
height
-
1
,
width
-
1
)).
T
.
reshape
(
-
1
,
2
)
pattern_points
*=
square_size
else
:
print
(
"unknown pattern"
)
return
None
obj_points
=
[]
img_points
=
[]
h
,
w
=
cv
.
imread
(
img_names
[
0
],
cv
.
IMREAD_GRAYSCALE
).
shape
[:
2
]
# TODO: use imquery call to retrieve results
aruco_dicts
=
{
'DICT_4X4_50'
:
cv
.
aruco
.
DICT_4X4_50
,
'DICT_4X4_100'
:
cv
.
aruco
.
DICT_4X4_100
,
'DICT_4X4_250'
:
cv
.
aruco
.
DICT_4X4_250
,
'DICT_4X4_1000'
:
cv
.
aruco
.
DICT_4X4_1000
,
'DICT_5X5_50'
:
cv
.
aruco
.
DICT_5X5_50
,
'DICT_5X5_100'
:
cv
.
aruco
.
DICT_5X5_100
,
'DICT_5X5_250'
:
cv
.
aruco
.
DICT_5X5_250
,
'DICT_5X5_1000'
:
cv
.
aruco
.
DICT_5X5_1000
,
'DICT_6X6_50'
:
cv
.
aruco
.
DICT_6X6_50
,
'DICT_6X6_100'
:
cv
.
aruco
.
DICT_6X6_100
,
'DICT_6X6_250'
:
cv
.
aruco
.
DICT_6X6_250
,
'DICT_6X6_1000'
:
cv
.
aruco
.
DICT_6X6_1000
,
'DICT_7X7_50'
:
cv
.
aruco
.
DICT_7X7_50
,
'DICT_7X7_100'
:
cv
.
aruco
.
DICT_7X7_100
,
'DICT_7X7_250'
:
cv
.
aruco
.
DICT_7X7_250
,
'DICT_7X7_1000'
:
cv
.
aruco
.
DICT_7X7_1000
,
'DICT_ARUCO_ORIGINAL'
:
cv
.
aruco
.
DICT_ARUCO_ORIGINAL
,
'DICT_APRILTAG_16h5'
:
cv
.
aruco
.
DICT_APRILTAG_16h5
,
'DICT_APRILTAG_25h9'
:
cv
.
aruco
.
DICT_APRILTAG_25h9
,
'DICT_APRILTAG_36h10'
:
cv
.
aruco
.
DICT_APRILTAG_36h10
,
'DICT_APRILTAG_36h11'
:
cv
.
aruco
.
DICT_APRILTAG_36h11
'DICT_4X4_50'
:
cv
.
aruco
.
DICT_4X4_50
,
'DICT_4X4_100'
:
cv
.
aruco
.
DICT_4X4_100
,
'DICT_4X4_250'
:
cv
.
aruco
.
DICT_4X4_250
,
'DICT_4X4_1000'
:
cv
.
aruco
.
DICT_4X4_1000
,
'DICT_5X5_50'
:
cv
.
aruco
.
DICT_5X5_50
,
'DICT_5X5_100'
:
cv
.
aruco
.
DICT_5X5_100
,
'DICT_5X5_250'
:
cv
.
aruco
.
DICT_5X5_250
,
'DICT_5X5_1000'
:
cv
.
aruco
.
DICT_5X5_1000
,
'DICT_6X6_50'
:
cv
.
aruco
.
DICT_6X6_50
,
'DICT_6X6_100'
:
cv
.
aruco
.
DICT_6X6_100
,
'DICT_6X6_250'
:
cv
.
aruco
.
DICT_6X6_250
,
'DICT_6X6_1000'
:
cv
.
aruco
.
DICT_6X6_1000
,
'DICT_7X7_50'
:
cv
.
aruco
.
DICT_7X7_50
,
'DICT_7X7_100'
:
cv
.
aruco
.
DICT_7X7_100
,
'DICT_7X7_250'
:
cv
.
aruco
.
DICT_7X7_250
,
'DICT_7X7_1000'
:
cv
.
aruco
.
DICT_7X7_1000
,
'DICT_ARUCO_ORIGINAL'
:
cv
.
aruco
.
DICT_ARUCO_ORIGINAL
,
'DICT_APRILTAG_16h5'
:
cv
.
aruco
.
DICT_APRILTAG_16h5
,
'DICT_APRILTAG_25h9'
:
cv
.
aruco
.
DICT_APRILTAG_25h9
,
'DICT_APRILTAG_36h10'
:
cv
.
aruco
.
DICT_APRILTAG_36h10
,
'DICT_APRILTAG_36h11'
:
cv
.
aruco
.
DICT_APRILTAG_36h11
}
if
(
aruco_dict_name
not
in
set
(
aruco_dicts
.
keys
())):
...
...
@@ -130,19 +125,27 @@ def main():
if
found
:
term
=
(
cv
.
TERM_CRITERIA_EPS
+
cv
.
TERM_CRITERIA_COUNT
,
30
,
0.1
)
cv
.
cornerSubPix
(
img
,
corners
,
(
5
,
5
),
(
-
1
,
-
1
),
term
)
frame_img_points
=
corners
.
reshape
(
-
1
,
2
)
frame_obj_points
=
pattern_points
elif
pattern_type
==
'charucoboard'
:
corners
,
_charucoIds
,
_markerCorners_svg
,
_markerIds_svg
=
charuco_detector
.
detectBoard
(
img
)
if
(
len
(
corners
)
==
(
height
-
1
)
*
(
width
-
1
)):
corners
,
charucoIds
,
_
,
_
=
charuco_detector
.
detectBoard
(
img
)
if
(
len
(
corners
)
>
0
):
frame_obj_points
,
frame_img_points
=
board
.
matchImagePoints
(
corners
,
charucoIds
)
found
=
True
else
:
found
=
False
else
:
print
(
"unknown pattern type"
,
pattern_type
)
return
None
if
debug_dir
:
vis
=
cv
.
cvtColor
(
img
,
cv
.
COLOR_GRAY2BGR
)
cv
.
drawChessboardCorners
(
vis
,
pattern_size
,
corners
,
found
)
if
pattern_type
==
'chessboard'
:
cv
.
drawChessboardCorners
(
vis
,
pattern_size
,
corners
,
found
)
elif
pattern_type
==
'charucoboard'
:
cv
.
aruco
.
drawDetectedCornersCharuco
(
vis
,
corners
,
charucoIds
=
charucoIds
)
_path
,
name
,
_ext
=
splitfn
(
fn
)
outfile
=
os
.
path
.
join
(
debug_dir
,
name
+
'_
chess
.png'
)
outfile
=
os
.
path
.
join
(
debug_dir
,
name
+
'_
board
.png'
)
cv
.
imwrite
(
outfile
,
vis
)
if
not
found
:
...
...
@@ -150,7 +153,7 @@ def main():
return
None
print
(
' %s... OK'
%
fn
)
return
(
corners
.
reshape
(
-
1
,
2
),
pattern
_points
)
return
(
frame_img_points
,
frame_obj
_points
)
threads_num
=
int
(
args
.
get
(
'--threads'
))
if
threads_num
<=
1
:
...
...
@@ -177,7 +180,7 @@ def main():
print
(
''
)
for
fn
in
img_names
if
debug_dir
else
[]:
_path
,
name
,
_ext
=
splitfn
(
fn
)
img_found
=
os
.
path
.
join
(
debug_dir
,
name
+
'_
chess
.png'
)
img_found
=
os
.
path
.
join
(
debug_dir
,
name
+
'_
board
.png'
)
outfile
=
os
.
path
.
join
(
debug_dir
,
name
+
'_undistorted.png'
)
img
=
cv
.
imread
(
img_found
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录