Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenCV
opencv
提交
0d455e05
O
opencv
项目概览
OpenCV
/
opencv
上一次同步 大约 1 年
通知
1005
Star
71102
Fork
55580
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d455e05
编写于
3月 15, 2023
作者:
A
Alex
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add py charuco sample+choriginal.jpg+camera_params
上级
a9d02f09
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
136 addition
and
0 deletion
+136
-0
samples/data/aruco/choriginal.jpg
samples/data/aruco/choriginal.jpg
+0
-0
samples/data/aruco/tutorial_camera_charuco.yml
samples/data/aruco/tutorial_camera_charuco.yml
+21
-0
samples/python/aruco_detect_board_charuco.py
samples/python/aruco_detect_board_charuco.py
+115
-0
未找到文件。
samples/data/aruco/choriginal.jpg
0 → 100644
浏览文件 @
0d455e05
此差异由.gitattributes 抑制。
samples/data/aruco/tutorial_camera_charuco.yml
0 → 100644
浏览文件 @
0d455e05
%YAML
:1.0
---
calibration_time: "Wed 08 Dec 2021 05:13:09 PM MSK"
image_width: 640
image_height: 480
flags: 0
camera_matrix: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [
4.5251072219637672
e+02,
0.,
3.1770297317353277e+02,
0.,
4.5676707935146891e+02, 2.7775155919135995e+02, 0., 0., 1. ]
distortion_coefficients
:
!!opencv-matrix
rows
:
1
cols
:
5
dt
:
d
data
:
[
1.2136925618707872e-01
,
-1.0854664722560681e+00
,
1.1786843796668460e-04
,
-4.6240686046485508e-04
,
2.9542589406810080e+00
]
avg_reprojection_error
:
1.8234905535936044e-01
info
:
"
The
camera
calibration
parameters
were
obtained
by
img_00.jpg-img_03.jpg
from
aruco/tutorials/aruco_calibration/images"
samples/python/aruco_detect_board_charuco.py
0 → 100644
浏览文件 @
0d455e05
#!/usr/bin/env python
"""aruco_detect_board_charuco.py
Usage example:
python aruco_detect_board_charuco.py -w=5 -h=7 -sl=0.04 -ml=0.02 -d=10 -c=../data/aruco/tutorial_camera_charuco.yml
-i=../data/aruco/choriginal.jpg
"""
import
argparse
import
numpy
as
np
import
cv2
as
cv
import
sys
def
read_camera_parameters
(
filename
):
fs
=
cv
.
FileStorage
(
cv
.
samples
.
findFile
(
filename
,
False
),
cv
.
FileStorage_READ
)
if
fs
.
isOpened
():
cam_matrix
=
fs
.
getNode
(
"camera_matrix"
).
mat
()
dist_coefficients
=
fs
.
getNode
(
"distortion_coefficients"
).
mat
()
return
True
,
cam_matrix
,
dist_coefficients
return
False
,
[],
[]
def
main
():
# parse command line options
parser
=
argparse
.
ArgumentParser
(
description
=
"detect markers and corners of charuco board, estimate pose of charuco"
"board"
,
add_help
=
False
)
parser
.
add_argument
(
"-H"
,
"--help"
,
help
=
"show help"
,
action
=
"store_true"
,
dest
=
"show_help"
)
parser
.
add_argument
(
"-v"
,
"--video"
,
help
=
"Input from video or image file, if omitted, input comes from camera"
,
default
=
""
,
action
=
"store"
,
dest
=
"v"
)
parser
.
add_argument
(
"-i"
,
"--image"
,
help
=
"Input from image file"
,
default
=
""
,
action
=
"store"
,
dest
=
"img_path"
)
parser
.
add_argument
(
"-w"
,
help
=
"Number of squares in X direction"
,
default
=
"3"
,
action
=
"store"
,
dest
=
"w"
,
type
=
int
)
parser
.
add_argument
(
"-h"
,
help
=
"Number of squares in Y direction"
,
default
=
"3"
,
action
=
"store"
,
dest
=
"h"
,
type
=
int
)
parser
.
add_argument
(
"-sl"
,
help
=
"Square side length"
,
default
=
"1."
,
action
=
"store"
,
dest
=
"sl"
,
type
=
float
)
parser
.
add_argument
(
"-ml"
,
help
=
"Marker side length"
,
default
=
"0.5"
,
action
=
"store"
,
dest
=
"ml"
,
type
=
float
)
parser
.
add_argument
(
"-d"
,
help
=
"dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2, DICT_4X4_1000=3,"
"DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, DICT_6X6_50=8,"
"DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12, DICT_7X7_100=13,"
"DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
,
default
=
"0"
,
action
=
"store"
,
dest
=
"d"
,
type
=
int
)
parser
.
add_argument
(
"-ci"
,
help
=
"Camera id if input doesnt come from video (-v)"
,
default
=
"0"
,
action
=
"store"
,
dest
=
"ci"
,
type
=
int
)
parser
.
add_argument
(
"-c"
,
help
=
"Input file with calibrated camera parameters"
,
default
=
""
,
action
=
"store"
,
dest
=
"cam_param"
)
args
=
parser
.
parse_args
()
show_help
=
args
.
show_help
if
show_help
:
parser
.
print_help
()
sys
.
exit
()
width
=
args
.
w
height
=
args
.
h
sqruare_len
=
args
.
sl
marker_len
=
args
.
ml
dict
=
args
.
d
video
=
args
.
v
camera_id
=
args
.
ci
img_path
=
args
.
img_path
cam_param
=
args
.
cam_param
cam_matrix
=
[]
dist_coefficients
=
[]
if
cam_param
!=
""
:
_
,
cam_matrix
,
dist_coefficients
=
read_camera_parameters
(
cam_param
)
aruco_dict
=
cv
.
aruco
.
getPredefinedDictionary
(
dict
)
board_size
=
(
width
,
height
)
board
=
cv
.
aruco
.
CharucoBoard
(
board_size
,
sqruare_len
,
marker_len
,
aruco_dict
)
charuco_detector
=
cv
.
aruco
.
CharucoDetector
(
board
)
image
=
None
input_video
=
None
wait_time
=
10
if
video
!=
""
:
input_video
=
cv
.
VideoCapture
(
cv
.
samples
.
findFileOrKeep
(
video
,
False
))
image
=
input_video
.
retrieve
()[
1
]
if
input_video
.
grab
()
else
None
elif
img_path
==
""
:
input_video
=
cv
.
VideoCapture
(
camera_id
)
image
=
input_video
.
retrieve
()[
1
]
if
input_video
.
grab
()
else
None
elif
img_path
!=
""
:
wait_time
=
0
image
=
cv
.
imread
(
cv
.
samples
.
findFile
(
img_path
,
False
))
if
image
is
None
:
print
(
"Error: unable to open video/image source"
)
sys
.
exit
(
0
)
while
image
is
not
None
:
image_copy
=
np
.
copy
(
image
)
charuco_corners
,
charuco_ids
,
marker_corners
,
marker_ids
=
charuco_detector
.
detectBoard
(
image
)
if
not
(
marker_ids
is
None
)
and
len
(
marker_ids
)
>
0
:
cv
.
aruco
.
drawDetectedMarkers
(
image_copy
,
marker_corners
)
if
not
(
charuco_ids
is
None
)
and
len
(
charuco_ids
)
>
0
:
cv
.
aruco
.
drawDetectedCornersCharuco
(
image_copy
,
charuco_corners
,
charuco_ids
)
if
len
(
cam_matrix
)
>
0
and
len
(
charuco_ids
)
>=
4
:
try
:
obj_points
,
img_points
=
board
.
matchImagePoints
(
charuco_corners
,
charuco_ids
)
flag
,
rvec
,
tvec
=
cv
.
solvePnP
(
obj_points
,
img_points
,
cam_matrix
,
dist_coefficients
)
if
flag
:
cv
.
drawFrameAxes
(
image_copy
,
cam_matrix
,
dist_coefficients
,
rvec
,
tvec
,
.
2
)
except
cv
.
error
as
error_inst
:
print
(
"SolvePnP recognize calibration pattern as non-planar pattern. To process this need to use "
"minimum 6 points. The planar pattern may be mistaken for non-planar if the pattern is "
"deformed or incorrect camera parameters are used."
)
print
(
error_inst
.
err
)
cv
.
imshow
(
"out"
,
image_copy
)
key
=
cv
.
waitKey
(
wait_time
)
if
key
==
27
:
break
image
=
input_video
.
retrieve
()[
1
]
if
input_video
is
not
None
and
input_video
.
grab
()
else
None
if
__name__
==
"__main__"
:
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录