cvl-robot's diary

研究ノート メモメモ https://github.com/dotchang/

OpenCV3.4のChArUcoのPoseEstimationを試す

detect_board_charucoのビルド

ビルド方法は同様に、

cd ~/opencv_contrib/modules/aruco/samples
g++ -o detect_board_charuco detect_board_charuco.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`

引数

> ./detect_board_charuco
Pose estimation using a ChArUco board
Usage: detect_board_charuco [params]

-c
Output file with calibrated camera parameters
--ci (value:0)
Camera id if input doesnt come from video (-v)
-d
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
--dp
File of marker detector parameters
-h
Number of squares in Y direction
--ml
Marker side length (in meters)
-r
show rejected candidates too
--rs
Apply refind strategy
--sl
Square side length (in meters)
-v
Input from video file, if ommited, input comes from camera
-w
Number of squares in X direction

実行

先にキャリブレーションした結果のファイル名を-cオプションで渡してあげます。

> ./detect_board_charuco -w=5 -h=7 -sl=0.034 -ml=0.0205 -d=10 --ci=2 -c=./test.xml

Detection Time = 39.9441 ms (Mean = 22.1969 ms)
Detection Time = 14.2675 ms (Mean = 22.1971 ms)
Detection Time = 25.2733 ms (Mean = 22.1978 ms)
Detection Time = 32.9801 ms (Mean = 22.1985 ms)
Detection Time = 30.8205 ms (Mean = 22.1995 ms)
Detection Time = 17.6587 ms (Mean = 22.2005 ms)

概ね、ビデオレートで実行できていることがわかります。ただしく姿勢推定に成功すると、ボードの角に大きな座標系が表示されます。キャリブレーション結果を渡さないなどした場合は、矢印は表示されません。
f:id:cvl-robot:20180129202416p:plain

出力結果の取得

姿勢推定の結果は、aruco::estimatePoseCharucoBoard()関数の引数、rvecとtvecに格納されています。これの正体がよく分からないので調べてみると、本家のページ(https://www.uco.es/investiga/grupos/ava/node/26の下の方)
に説明がありました。Rvecをロドリゲス変換して、

cv::Rodrigues(Rvec,R33);
T=[ R00 R01 R01 T0;R10 R11 R11 T1;R20 R21 R21 T2; 0 0 0 1]

だそうです。説明の行列の添字がなんかおかしい気がしますね。3番めはそれぞれR02, R12, R22であってほしい。

R00 R01 R01 T0
R10 R11 R11 T1
R20 R21 R21 R2
0 0 0 1

JVR ― 自腹でバーチャルリアリティ ― OpenCVの座標系とOpenGLの座標系