31 for( k = 0; k < patt->
loop_num; k++ ) {
32 for( j = 0; j < patt->
v_num; j++ ) {
33 for( i = 0; i < patt->
h_num; i++ ) {
34 ARToolKitPlus::Tracker::arParamObserv2Ideal( dist_factor,
45 for( j = 0; j < patt->
v_num; j++ ) {
46 for( i = 0; i < patt->
h_num; i++ ) {
52 minerr = (
ARFloat)100000000000000000000000.0;
53 for( j = -50; j <= 50; j++ ) {
54 printf(
"-- loop:%d --\n", j);
55 y0 = dist_factor[1] + j;
57 if( y0 < 0 || y0 >= ysize )
continue;
59 for( i = -50; i <= 50; i++ ) {
60 x0 = dist_factor[0] + i;
62 if( x0 < 0 || x0 >= xsize )
continue;
64 res =
calc_inp2( patt, screen, pos2d, pos3d, dist_factor, x0, y0, f, &err );
65 if( res < 0 )
continue;
67 printf(
"F = (%f,%f), Center = (%f,%f): err = %f\n", f[0], f[1], x0, y0, err);
90 if( minerr >= 100.0 )
return -1;
102 ARFloat cpara[3][4], conv[3][4];
103 ARFloat ppos2d[4][2], ppos3d[4][2];
107 for( i = 0; i < patt->
loop_num; i++ ) {
110 x1 = para[0][0] / para[2][0];
111 y1 = para[1][0] / para[2][0];
112 x2 = para[0][1] / para[2][1];
113 y2 = para[1][1] / para[2][1];
115 p[i] = (x1 - x0)*(x2 - x0);
116 q[i] = (y1 - y0)*(y2 - y0);
134 for( i = 0; i < patt->
loop_num; i++ ) {
137 rot[0][0] = (para[0][0] - x0*para[2][0]) / f[0];
138 rot[0][1] = (para[1][0] - y0*para[2][0]) / f[1];
139 rot[0][2] = para[2][0];
140 d = (
ARFloat)sqrt( rot[0][0]*rot[0][0] + rot[0][1]*rot[0][1] + rot[0][2]*rot[0][2] );
144 rot[1][0] = (para[0][1] - x0*para[2][1]) / f[0];
145 rot[1][1] = (para[1][1] - y0*para[2][1]) / f[1];
146 rot[1][2] = para[2][1];
147 d = (
ARFloat)sqrt( rot[1][0]*rot[1][0] + rot[1][1]*rot[1][1] + rot[1][2]*rot[1][2] );
152 rot[2][0] = rot[0][1]*rot[1][2] - rot[0][2]*rot[1][1];
153 rot[2][1] = rot[0][2]*rot[1][0] - rot[0][0]*rot[1][2];
154 rot[2][2] = rot[0][0]*rot[1][1] - rot[0][1]*rot[1][0];
155 d = (
ARFloat)sqrt( rot[2][0]*rot[2][0] + rot[2][1]*rot[2][1] + rot[2][2]*rot[2][2] );
159 rot2[0][0] = rot[0][0];
160 rot2[1][0] = rot[0][1];
161 rot2[2][0] = rot[0][2];
162 rot2[0][1] = rot[1][0];
163 rot2[1][1] = rot[1][1];
164 rot2[2][1] = rot[1][2];
165 rot2[0][2] = rot[2][0];
166 rot2[1][2] = rot[2][1];
167 rot2[2][2] = rot[2][2];
169 ppos2d[0][0] = pos2d[i*patt->
h_num*patt->
v_num*2 + 0];
170 ppos2d[0][1] = pos2d[i*patt->
h_num*patt->
v_num*2 + 1];
171 ppos2d[1][0] = pos2d[i*patt->
h_num*patt->
v_num*2 + (patt->
h_num-1)*2 + 0];
172 ppos2d[1][1] = pos2d[i*patt->
h_num*patt->
v_num*2 + (patt->
h_num-1)*2 + 1];
177 ppos3d[0][0] = pos3d[0];
178 ppos3d[0][1] = pos3d[1];
179 ppos3d[1][0] = pos3d[(patt->
h_num-1)*2 + 0];
180 ppos3d[1][1] = pos3d[(patt->
h_num-1)*2 + 1];
181 ppos3d[2][0] = pos3d[(patt->
h_num*(patt->
v_num-1))*2 + 0];
182 ppos3d[2][1] = pos3d[(patt->
h_num*(patt->
v_num-1))*2 + 1];
183 ppos3d[3][0] = pos3d[(patt->
h_num*patt->
v_num-1)*2 + 0];
184 ppos3d[3][1] = pos3d[(patt->
h_num*patt->
v_num-1)*2 + 1];
186 for( j = 0; j < 5; j++ ) {
188 werr2 = theTracker->arGetTransMat3( rot2, ppos2d, ppos3d, 4, conv, dist_factor, cpara );
189 for( k = 0; k < 3; k++ ) {
190 for( l = 0; l < 3; l++ ) {
191 rot2[k][l] = conv[k][l];
213 for( i = 0; i < num; i++ ) {
233 ARToolKitPlus::Matrix::trans( at, a );
239 res.
m = &(para[0][0]);
263 for( i = 0; i < num; i++ ) {
264 a->
m[i*2+0] = *(p++);
265 a->
m[i*2+1] = *(q++);
276 for( i = 0; i < num-1; i++ ) {
277 a->
m[i*2+0] = *(p++);
278 a->
m[i*2+1] = *(q++);
282 ARToolKitPlus::Matrix::trans( at, a );
288 if( res->
m[0] < 0 || res->
m[1] < 0 )
return -1;
290 f[0] = (
ARFloat)sqrt( 1.0 / res->
m[0] );
291 f[1] = (
ARFloat)sqrt( 1.0 / res->
m[1] );
306 ARFloat ca, cb, k1, k2, k3, k4;
322 v3[0] = v1[1]*v2[2] - v1[2]*v2[1];
323 v3[1] = v1[2]*v2[0] - v1[0]*v2[2];
324 v3[2] = v1[0]*v2[1] - v1[1]*v2[0];
325 w = (
ARFloat)sqrt( v3[0]*v3[0]+v3[1]*v3[1]+v3[2]*v3[2] );
326 if( w == 0.0 )
return -1;
331 cb = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
332 if( cb < 0 ) cb *= -1.0;
335 if( v3[1]*v1[0] - v1[1]*v3[0] != 0.0 ) {
339 if( v3[2]*v1[0] - v1[2]*v3[0] != 0.0 ) {
340 w = v1[1]; v1[1] = v1[2]; v1[2] = w;
341 w = v3[1]; v3[1] = v3[2]; v3[2] = w;
345 w = v1[0]; v1[0] = v1[2]; v1[2] = w;
346 w = v3[0]; v3[0] = v3[2]; v3[2] = w;
350 if( v3[1]*v1[0] - v1[1]*v3[0] == 0.0 )
return -1;
351 k1 = (v1[1]*v3[2] - v3[1]*v1[2]) / (v3[1]*v1[0] - v1[1]*v3[0]);
352 k2 = (v3[1] * ca) / (v3[1]*v1[0] - v1[1]*v3[0]);
353 k3 = (v1[0]*v3[2] - v3[0]*v1[2]) / (v3[0]*v1[1] - v1[0]*v3[1]);
354 k4 = (v3[0] * ca) / (v3[0]*v1[1] - v1[0]*v3[1]);
356 a = k1*k1 + k3*k3 + 1;
358 c = k2*k2 + k4*k4 - 1;
361 if( d < 0 )
return -1;
362 r1 = (-b + (
ARFloat)sqrt(d))/a;
365 r2 = (-b - (
ARFloat)sqrt(d))/a;
369 w = q1; q1 = r1; r1 = w;
370 w = q2; q2 = r2; r2 = w;
371 w = v1[1]; v1[1] = v1[2]; v1[2] = w;
372 w = v3[1]; v3[1] = v3[2]; v3[2] = w;
376 w = p1; p1 = r1; r1 = w;
377 w = p2; p2 = r2; r2 = w;
378 w = v1[0]; v1[0] = v1[2]; v1[2] = w;
379 w = v3[0]; v3[0] = v3[2]; v3[2] = w;
383 if( v3[1]*v2[0] - v2[1]*v3[0] != 0.0 ) {
387 if( v3[2]*v2[0] - v2[2]*v3[0] != 0.0 ) {
388 w = v2[1]; v2[1] = v2[2]; v2[2] = w;
389 w = v3[1]; v3[1] = v3[2]; v3[2] = w;
393 w = v2[0]; v2[0] = v2[2]; v2[2] = w;
394 w = v3[0]; v3[0] = v3[2]; v3[2] = w;
398 if( v3[1]*v2[0] - v2[1]*v3[0] == 0.0 )
return -1;
399 k1 = (v2[1]*v3[2] - v3[1]*v2[2]) / (v3[1]*v2[0] - v2[1]*v3[0]);
400 k2 = (v3[1] * ca) / (v3[1]*v2[0] - v2[1]*v3[0]);
401 k3 = (v2[0]*v3[2] - v3[0]*v2[2]) / (v3[0]*v2[1] - v2[0]*v3[1]);
402 k4 = (v3[0] * ca) / (v3[0]*v2[1] - v2[0]*v3[1]);
404 a = k1*k1 + k3*k3 + 1;
406 c = k2*k2 + k4*k4 - 1;
409 if( d < 0 )
return -1;
410 r3 = (-b + (
ARFloat)sqrt(d))/a;
413 r4 = (-b - (
ARFloat)sqrt(d))/a;
417 w = q3; q3 = r3; r3 = w;
418 w = q4; q4 = r4; r4 = w;
419 w = v2[1]; v2[1] = v2[2]; v2[2] = w;
420 w = v3[1]; v3[1] = v3[2]; v3[2] = w;
424 w = p3; p3 = r3; r3 = w;
425 w = p4; p4 = r4; r4 = w;
426 w = v2[0]; v2[0] = v2[2]; v2[2] = w;
427 w = v3[0]; v3[0] = v3[2]; v3[2] = w;
431 e1 = p1*p3+q1*q3+r1*r3;
if( e1 < 0 ) e1 = -e1;
432 e2 = p1*p4+q1*q4+r1*r4;
if( e2 < 0 ) e2 = -e2;
433 e3 = p2*p3+q2*q3+r2*r3;
if( e3 < 0 ) e3 = -e3;
434 e4 = p2*p4+q2*q4+r2*r4;
if( e4 < 0 ) e4 = -e4;
static int calc_inp2(CALIB_PATT_T *patt, CALIB_COORD_T *screen, ARFloat *pos2d, ARFloat *pos3d, ARFloat dist_factor[4], ARFloat x0, ARFloat y0, ARFloat f[2], ARFloat *err)
static int get_fl(ARFloat *p, ARFloat *q, int num, ARFloat f[2])
static void get_cpara(CALIB_COORD_T *world, CALIB_COORD_T *screen, int num, ARFloat para[3][3])
static int check_rotation(ARFloat rot[2][3])
ARToolKitPlus::Tracker * theTracker
int calc_inp(CALIB_PATT_T *patt, ARFloat dist_factor[4], int xsize, int ysize, ARFloat mat[3][4])
CALIB_COORD_T * point[LOOP_MAX]
TFSIMD_FORCE_INLINE const tfScalar & w() const
#define AR_FITTING_TO_IDEAL
CALIB_COORD_T * world_coord