@@ -38,107 +38,10 @@ the use of this software, even if advised of the possibility of such damage.
38
38
39
39
40
40
#include " test_precomp.hpp"
41
+ #include " test_aruco_utils.hpp"
41
42
42
43
namespace opencv_test { namespace {
43
44
44
- static double deg2rad (double deg) { return deg * CV_PI / 180 .; }
45
-
46
- /* *
47
- * @brief Get rvec and tvec from yaw, pitch and distance
48
- */
49
- static void getSyntheticRT (double yaw, double pitch, double distance, Mat &rvec, Mat &tvec) {
50
-
51
- rvec = Mat::zeros (3 , 1 , CV_64FC1);
52
- tvec = Mat::zeros (3 , 1 , CV_64FC1);
53
-
54
- // rotate camera in pitch axis
55
- Mat rotPitch (3 , 1 , CV_64FC1);
56
- rotPitch.ptr < double >(0 )[0 ] = pitch;
57
- rotPitch.ptr < double >(0 )[1 ] = 0 ;
58
- rotPitch.ptr < double >(0 )[2 ] = 0 ;
59
-
60
- // rotate camera in yaw axis
61
- Mat rotYaw (3 , 1 , CV_64FC1);
62
- rotYaw.ptr < double >(0 )[0 ] = 0 ;
63
- rotYaw.ptr < double >(0 )[1 ] = yaw;
64
- rotYaw.ptr < double >(0 )[2 ] = 0 ;
65
-
66
- // compose both rotations
67
- composeRT (rotPitch, Mat (3 , 1 , CV_64FC1, Scalar::all (0 )), rotYaw,
68
- Mat (3 , 1 , CV_64FC1, Scalar::all (0 )), rvec, tvec);
69
-
70
- // Tvec, just move in z (camera) direction the specific distance
71
- tvec.ptr < double >(0 )[0 ] = 0 .;
72
- tvec.ptr < double >(0 )[1 ] = 0 .;
73
- tvec.ptr < double >(0 )[2 ] = distance;
74
- }
75
-
76
- /* *
77
- * @brief Project a synthetic marker
78
- */
79
- static void projectMarker (Mat &img, Ptr <aruco::Board> &board, int markerIndex, Mat cameraMatrix, Mat rvec, Mat tvec,
80
- int markerBorder) {
81
- // canonical image
82
- Mat markerImg;
83
- const int markerSizePixels = 100 ;
84
- aruco::drawMarker (board->dictionary , board->ids [markerIndex], markerSizePixels, markerImg, markerBorder);
85
-
86
- // projected corners
87
- Mat distCoeffs (5 , 1 , CV_64FC1, Scalar::all (0 ));
88
- vector< Point2f > corners;
89
-
90
- // get max coordinate of board
91
- Point3f maxCoord = board->objPoints .back ()[2 ];
92
- vector<Point3f> objPoints (board->objPoints [markerIndex]);
93
- // move the marker to the origin
94
- for (size_t i = 0 ; i < objPoints.size (); i++)
95
- objPoints[i] -= maxCoord / 2.0 ;
96
-
97
- projectPoints (objPoints, rvec, tvec, cameraMatrix, distCoeffs, corners);
98
-
99
- // get perspective transform
100
- vector< Point2f > originalCorners;
101
- originalCorners.push_back (Point2f (0 , 0 ));
102
- originalCorners.push_back (Point2f ((float )markerSizePixels, 0 ));
103
- originalCorners.push_back (Point2f ((float )markerSizePixels, (float )markerSizePixels));
104
- originalCorners.push_back (Point2f (0 , (float )markerSizePixels));
105
- Mat transformation = getPerspectiveTransform (originalCorners, corners);
106
-
107
- // apply transformation
108
- Mat aux;
109
- const char borderValue = 127 ;
110
- warpPerspective (markerImg, aux, transformation, img.size (), INTER_NEAREST, BORDER_CONSTANT,
111
- Scalar::all (borderValue));
112
-
113
- // copy only not-border pixels
114
- for (int y = 0 ; y < aux.rows ; y++) {
115
- for (int x = 0 ; x < aux.cols ; x++) {
116
- if (aux.at < unsigned char >(y, x) == borderValue) continue ;
117
- img.at < unsigned char >(y, x) = aux.at < unsigned char >(y, x);
118
- }
119
- }
120
- }
121
-
122
-
123
- /* *
124
- * @brief Get a synthetic image of GridBoard in perspective
125
- */
126
- static Mat projectBoard (Ptr <aruco::GridBoard> &board, Mat cameraMatrix, double yaw, double pitch,
127
- double distance, Size imageSize, int markerBorder) {
128
-
129
- Mat rvec, tvec;
130
- getSyntheticRT (yaw, pitch, distance, rvec, tvec);
131
-
132
- Mat img = Mat (imageSize, CV_8UC1, Scalar::all (255 ));
133
- for (unsigned int index = 0 ; index < board->ids .size (); index ++) {
134
- projectMarker (img, board.staticCast <aruco::Board>(), index , cameraMatrix, rvec, tvec, markerBorder);
135
- }
136
-
137
- return img;
138
- }
139
-
140
-
141
-
142
45
/* *
143
46
* @brief Check pose estimation of aruco board
144
47
*/
@@ -169,7 +72,7 @@ void CV_ArucoBoardPose::run(int) {
169
72
// for different perspectives
170
73
for (double distance = 0.2 ; distance <= 0.4 ; distance += 0.2 ) {
171
74
for (int yaw = -60 ; yaw <= 60 ; yaw += 30 ) {
172
- for (int pitch = -0 ; pitch <= 0 ; pitch += 30 ) {
75
+ for (int pitch = -60 ; pitch <= 60 ; pitch += 30 ) {
173
76
for (unsigned int i = 0 ; i < gridboard->ids .size (); i++)
174
77
gridboard->ids [i] = (iter + int (i)) % 250 ;
175
78
int markerBorder = iter % 2 + 1 ;
@@ -270,8 +173,6 @@ void CV_ArucoRefine::run(int) {
270
173
// create synthetic image
271
174
Mat img = projectBoard (gridboard, cameraMatrix, deg2rad (yaw), deg2rad (pitch), distance,
272
175
imgSize, markerBorder);
273
-
274
-
275
176
// detect markers
276
177
vector< vector< Point2f > > corners, rejected;
277
178
vector< int > ids;
0 commit comments