11
11
#include < opencv2/aruco.hpp>
12
12
13
13
#define MARKER_SIDE 0.032
14
+ #define CAMERAS 2
14
15
15
16
using namespace std ;
16
17
using namespace cv ;
17
18
19
+ vector<Point3d> getCornersInCameraWorld (double side, Vec3d rvec, Vec3d tvec)
20
+ {
21
+ double half_side = side / 2 ;
22
+
23
+ // compute rot_mat
24
+ Mat rot_mat;
25
+ Rodrigues (rvec, rot_mat);
26
+
27
+ // transpose of rot_mat for easy columns extraction
28
+ Mat rot_mat_t = rot_mat.t ();
29
+
30
+ // the two E-O and F-O vectors
31
+ double * tmp = rot_mat_t .ptr <double >(0 );
32
+ Point3d camWorldE (tmp[0 ] * half_side,
33
+ tmp[1 ] * half_side,
34
+ tmp[2 ] * half_side);
35
+
36
+ tmp = rot_mat_t .ptr <double >(1 );
37
+ Point3d camWorldF (tmp[0 ] * half_side,
38
+ tmp[1 ] * half_side,
39
+ tmp[2 ] * half_side);
40
+
41
+ // convert tvec to point
42
+ Point3d tvec_3d (tvec[0 ], tvec[1 ], tvec[2 ]);
43
+
44
+ // return vector:
45
+ vector<Point3d> ret (4 , tvec_3d);
46
+
47
+ ret[0 ] += -camWorldE + camWorldF; // top left
48
+ ret[1 ] += camWorldE + camWorldF; // top right
49
+ ret[2 ] += camWorldE - camWorldF; // bottom right
50
+ ret[3 ] += -camWorldE - camWorldF; // bottom left
51
+
52
+ return ret;
53
+ }
54
+
18
55
int main ()
19
56
{
20
57
// get intrinsics
@@ -51,13 +88,14 @@ int main()
51
88
// get marker points
52
89
Ptr <aruco::Dictionary> dictionary = aruco::getPredefinedDictionary (aruco::DICT_4X4_100);
53
90
// vector<Point3d> object_points;
54
- vector<Point2f> image_points;
91
+ vector<Point2f> image_points[CAMERAS] ;
55
92
56
93
map<string, Mat> images;
57
94
58
95
59
- for_each ( begin (serial_numbers), end (serial_numbers), [&dictionary, /* &object_points, */ &image_points, &serial_numbers, &camera_matrix_map, &dist_coeffs_map, &images](string sn )
96
+ for ( int camera_idx= 0 ; camera_idx<CAMERAS; camera_idx++ )
60
97
{
98
+ string sn = serial_numbers[camera_idx];
61
99
string file_name = " ../Common/Image/IR/" + sn + " .png" ;
62
100
Mat image = imread (file_name);
63
101
images[sn] = image;
@@ -98,16 +136,19 @@ int main()
98
136
99
137
for (int i = 0 ; i < ids.size (); i++)
100
138
{
101
- if (sn == serial_numbers[1 ])
139
+ if (sn == serial_numbers[0 ])
102
140
{
103
- for (int j = 0 ; j < 4 ; j++)
104
- {
105
- image_points.push_back (corners[indices[i]][j]);
106
- }
141
+ // vector<Point3d> corners3D = getCornersInCameraWorld(MARKER_SIDE, rvecs[indices[i]], tvecs[indices[i]]);
142
+ // object_points.insert(object_points.end(), corners3D.begin(), corners3D.end());
143
+ }
144
+
145
+ for (int j = 0 ; j < 4 ; j++)
146
+ {
147
+ image_points[camera_idx].push_back (corners[indices[i]][j]);
107
148
}
108
149
}
109
150
}
110
- });
151
+ }
111
152
112
153
Mat camera_rvec, camera_rot, camera_tvec;
113
154
@@ -118,10 +159,7 @@ int main()
118
159
return -1 ;
119
160
}
120
161
121
- fs2[" R1" ] >> camera_rvec;
122
- fs2[" t1" ] >> camera_tvec;
123
-
124
- fs2.release ();
162
+
125
163
126
164
vector<Point3d> object_points;
127
165
FILE* fptr = fopen (" ../Common/Correspondence/test2/point3d.txt" , " r" );
@@ -131,36 +169,45 @@ int main()
131
169
exit (1 );
132
170
};
133
171
134
- int num_points;
135
- fscanf (fptr, " %d" , &num_points);
172
+ int num_points_all;
173
+ fscanf (fptr, " %d" , &num_points_all);
174
+ int num_points_per_camera = num_points_all / 2 ;
136
175
137
- for (int i = 0 ; i < num_points; i ++)
176
+ for (int camera_idx = 0 ; camera_idx < CAMERAS; camera_idx ++)
138
177
{
139
- Point3d point;
140
- fscanf (fptr, " %lf" , &point.x );
141
- fscanf (fptr, " %lf" , &point.y );
142
- fscanf (fptr, " %lf" , &point.z );
143
- object_points.emplace_back (point);
144
- }
145
- fclose (fptr);
178
+ object_points.clear ();
146
179
180
+ for (int i = 0 ; i < num_points_per_camera; i++)
181
+ {
182
+ Point3d point;
183
+ fscanf (fptr, " %lf" , &point.x );
184
+ fscanf (fptr, " %lf" , &point.y );
185
+ fscanf (fptr, " %lf" , &point.z );
186
+ object_points.emplace_back (point);
187
+ }
147
188
148
- vector<Point2d> reprojected_points ;
149
- projectPoints (object_points, camera_rvec, camera_tvec, camera_matrix_map[serial_numbers[ 1 ]], dist_coeffs_map[serial_numbers[ 1 ]], reprojected_points) ;
189
+ fs2[ " R " + to_string (camera_idx)] >> camera_rvec ;
190
+ fs2[ " t " + to_string (camera_idx)] >> camera_tvec ;
150
191
151
- // visualization
152
- Mat reprojection_image = images[serial_numbers[1 ]];
153
- for (int i = 0 ; i < reprojected_points.size (); i++)
154
- {
155
- drawMarker (reprojection_image, image_points[i], Scalar (255 , 0 , 0 ), MARKER_CROSS, 10 , 2 );
156
- drawMarker (reprojection_image, reprojected_points[i], Scalar (0 , 255 , 0 ), MARKER_CROSS, 10 , 2 );
157
- }
192
+ vector<Point2d> reprojected_points;
193
+ projectPoints (object_points, camera_rvec, camera_tvec, camera_matrix_map[serial_numbers[camera_idx]], dist_coeffs_map[serial_numbers[camera_idx]], reprojected_points);
158
194
159
- putText (reprojection_image, " BLUE : Marker Points (t+1)" , Point { 10 ,20 }, FONT_HERSHEY_SIMPLEX, 0.7 , Scalar (255 , 0 , 0 ), 2 );
160
- putText (reprojection_image, " GREEN : Reprojected Points (t -> t+1)" , Point { 10 ,45 }, FONT_HERSHEY_SIMPLEX, 0.7 , Scalar (0 , 255 , 0 ), 2 );
195
+ // visualization
196
+ Mat reprojection_image = images[serial_numbers[camera_idx]];
197
+ for (int i = 0 ; i < reprojected_points.size (); i++)
198
+ {
199
+ drawMarker (reprojection_image, image_points[camera_idx][i], Scalar (255 , 0 , 0 ), MARKER_CROSS, 10 , 2 );
200
+ drawMarker (reprojection_image, reprojected_points[i], Scalar (0 , 255 , 0 ), MARKER_CROSS, 10 , 2 );
201
+ }
161
202
162
- imshow (" Reprojection" , reprojection_image);
203
+ putText (reprojection_image, " BLUE : Marker Points (t+1)" , Point { 10 ,20 }, FONT_HERSHEY_SIMPLEX, 0.7 , Scalar (255 , 0 , 0 ), 2 );
204
+ putText (reprojection_image, " GREEN : Reprojected Points (t -> t+1)" , Point { 10 ,45 }, FONT_HERSHEY_SIMPLEX, 0.7 , Scalar (0 , 255 , 0 ), 2 );
163
205
206
+ imshow (" Reprojection: " + serial_numbers[camera_idx], reprojection_image);
207
+ }
208
+
209
+ fclose (fptr);
210
+ fs2.release ();
164
211
165
212
while (true )
166
213
{
0 commit comments