42 #include <visp/vpHomography.h>
43 #include <visp/vpMath.h>
51 const double vpHomography::sing_threshold = 0.0001;
71 nd[0]=0;nd[1]=0;nd[2]=1;
105 #ifndef DOXYGEN_SHOULD_SKIP_THIS
142 double distanceFictive;
143 double sinusTheta, cosinusTheta, signeSinus= 1;
144 double cosinusDesireeEstimee, cosinusAncien;
145 double s, determinantU, determinantV;
146 unsigned int i, j, k, w;
147 unsigned int vOrdre[3];
154 #ifdef DEBUG_Homographie
155 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
167 for (i=0 ; i < 3 ; i++)
168 for (j=0 ; j < 3 ; j++) mH[i][j] = aHb[i][j];
178 mTempU.svd(svTemp,mTempV) ;
183 if (svTemp[0] >= svTemp[1]) {
184 if (svTemp[0] >= svTemp[2]) {
185 if (svTemp[1] > svTemp[2]) {
186 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
188 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
191 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
194 if (svTemp[1] >= svTemp[2]){
195 if (svTemp[0] > svTemp[2])
196 { vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2; }
198 { vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0; }
200 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
210 for (i = 0; i < 3; i++) {
211 sv[i] = svTemp[vOrdre[i]];
212 for (j = 0; j < 3; j++) {
213 mU[i][j] = mTempU[i][vOrdre[j]];
214 mV[i][j] = mTempV[i][vOrdre[j]];
218 #ifdef DEBUG_Homographie
219 printf(
"U : \n") ; std::cout << mU << std::endl ;
220 printf(
"V : \n") ; std::cout << mV << std::endl ;
221 printf(
"Valeurs singulieres : ") ; std::cout << sv.t() ;
225 determinantV = mV.det();
226 determinantU = mU.det();
228 s = determinantU * determinantV;
230 #ifdef DEBUG_Homographie
231 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
237 distanceFictive = sv[1];
238 #ifdef DEBUG_Homographie
239 printf (
"d = %f\n",distanceFictive);
243 if (((sv[0] - sv[1]) < sing_threshold) && (sv[0] - sv[2]) < sing_threshold)
257 n[0] = normaleDesiree[0];
258 n[1] = normaleDesiree[1];
259 n[2] = normaleDesiree[2];
263 #ifdef DEBUG_Homographie
264 printf(
"\nCas general\n");
278 mX[0][0] = sqrt ((sv[0] * sv[0] - sv[1] * sv[1])
279 / (sv[0] * sv[0] - sv[2] * sv[2]));
281 mX[2][0] = sqrt ((sv[1] * sv[1] - sv[2] * sv[2])
282 / (sv[0] * sv[0] - sv[2] * sv[2]));
284 mX[0][1] = -mX[0][0];
290 for (w = 0; w < 2; w++) {
291 for (k = 0; k < 2; k++) {
294 for (i = 0; i < 3; i++) {
295 normaleEstimee[i] = 0.0;
296 for (j = 0; j < 3; j++) {
297 normaleEstimee[i] += (2.0 * k - 1.0) * mV[i][j] * mX[j][w];
303 cosinusDesireeEstimee = 0.0;
304 for (i = 0; i < 3; i++)
305 cosinusDesireeEstimee += normaleEstimee[i] * normaleDesiree[i];
311 if (cosinusDesireeEstimee > cosinusAncien)
313 cosinusAncien = cosinusDesireeEstimee;
316 for (j = 0; j < 3; j++)
317 n[j] = normaleEstimee[j];
320 aTbp[0] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[0][w];
321 aTbp[1] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[1][w];
322 aTbp[2] = -(2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[2][w];
336 for (i = 0; i < 3; i++) {
338 for (j = 0; j < 3; j++) {
339 atb[i] += mU[i][j] * aTbp[j];
341 atb[i] /= distanceFictive;
345 #ifdef DEBUG_Homographie
346 printf(
"t' : ") ; std::cout << aTbp.t() ;
347 printf(
"t/d : ") ; std::cout << atb.
t() ;
348 printf(
"n : ") ; std::cout << n.
t() ;
359 sinusTheta = signeSinus*sqrt((sv[0]*sv[0] -sv[1]*sv[1])
360 *(sv[1]*sv[1] -sv[2]*sv[2]))
361 / ((sv[0] + sv[2]) * sv[1]);
363 cosinusTheta = ( sv[1] * sv[1] + sv[0] * sv[2] ) / ((sv[0] + sv[2]) * sv[1]);
366 aRbp[0][0] = cosinusTheta; aRbp[0][1] = 0; aRbp[0][2] = -sinusTheta;
367 aRbp[1][0] = 0; aRbp[1][1] = 1; aRbp[1][2] = 0;
368 aRbp[2][0] = sinusTheta; aRbp[2][1] = 0; aRbp[2][2] = cosinusTheta;
373 for (i = 0; i < 3; i++) {
374 for (j = 0; j < 3; j++) {
376 for (k = 0; k < 3; k++) {
377 aRbint[i][j] += mU[i][k] * aRbp[k][j];
383 for (i = 0; i < 3; i++) {
384 for (j = 0; j < 3; j++) {
386 for (k = 0; k < 3; k++) {
387 aRb[i][j] += aRbint[i][k] * mV[j][k];
392 #ifdef DEBUG_Homographie
428 double distanceFictive;
429 double sinusTheta, cosinusTheta, signeSinus= 1;
430 double cosinusDesireeEstimee, cosinusAncien;
431 double s, determinantU, determinantV;
432 unsigned int i, j, k, w;
433 unsigned int vOrdre[3];
436 normaleDesiree[0]=0;normaleDesiree[1]=0;normaleDesiree[2]=1;
439 #ifdef DEBUG_Homographie
440 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
452 for (i=0 ; i < 3 ; i++)
453 for (j=0 ; j < 3 ; j++) mH[i][j] = aHb[i][j];
463 mTempU.svd(svTemp,mTempV) ;
468 if (svTemp[0] >= svTemp[1]) {
469 if (svTemp[0] >= svTemp[2]) {
470 if (svTemp[1] > svTemp[2]) {
471 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
473 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
476 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
479 if (svTemp[1] >= svTemp[2]){
480 if (svTemp[0] > svTemp[2])
481 { vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2; }
483 { vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0; }
485 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
495 for (i = 0; i < 3; i++) {
496 sv[i] = svTemp[vOrdre[i]];
497 for (j = 0; j < 3; j++) {
498 mU[i][j] = mTempU[i][vOrdre[j]];
499 mV[i][j] = mTempV[i][vOrdre[j]];
503 #ifdef DEBUG_Homographie
504 printf(
"U : \n") ; std::cout << mU << std::endl ;
505 printf(
"V : \n") ; std::cout << mV << std::endl ;
506 printf(
"Valeurs singulieres : ") ; std::cout << sv.t() ;
510 determinantV = mV.det();
511 determinantU = mU.det();
513 s = determinantU * determinantV;
515 #ifdef DEBUG_Homographie
516 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
522 distanceFictive = sv[1];
523 #ifdef DEBUG_Homographie
524 printf (
"d = %f\n",distanceFictive);
528 if (((sv[0] - sv[1]) < sing_threshold) && (sv[0] - sv[2]) < sing_threshold)
542 n[0] = normaleDesiree[0];
543 n[1] = normaleDesiree[1];
544 n[2] = normaleDesiree[2];
548 #ifdef DEBUG_Homographie
549 printf(
"\nCas general\n");
563 mX[0][0] = sqrt ((sv[0] * sv[0] - sv[1] * sv[1])
564 / (sv[0] * sv[0] - sv[2] * sv[2]));
566 mX[2][0] = sqrt ((sv[1] * sv[1] - sv[2] * sv[2])
567 / (sv[0] * sv[0] - sv[2] * sv[2]));
569 mX[0][1] = -mX[0][0];
575 for (w = 0; w < 2; w++) {
576 for (k = 0; k < 2; k++) {
579 for (i = 0; i < 3; i++) {
580 normaleEstimee[i] = 0.0;
581 for (j = 0; j < 3; j++) {
582 normaleEstimee[i] += (2.0 * k - 1.0) * mV[i][j] * mX[j][w];
588 cosinusDesireeEstimee = 0.0;
589 for (i = 0; i < 3; i++)
590 cosinusDesireeEstimee += normaleEstimee[i] * normaleDesiree[i];
596 if (cosinusDesireeEstimee > cosinusAncien)
598 cosinusAncien = cosinusDesireeEstimee;
601 for (j = 0; j < 3; j++)
602 n[j] = normaleEstimee[j];
605 aTbp[0] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[0][w];
606 aTbp[1] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[1][w];
607 aTbp[2] = -(2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[2][w];
621 for (i = 0; i < 3; i++) {
623 for (j = 0; j < 3; j++) {
624 atb[i] += mU[i][j] * aTbp[j];
626 atb[i] /= distanceFictive;
630 #ifdef DEBUG_Homographie
631 printf(
"t' : ") ; std::cout << aTbp.t() ;
632 printf(
"t/d : ") ; std::cout << atb.
t() ;
633 printf(
"n : ") ; std::cout << n.
t() ;
644 sinusTheta = signeSinus*sqrt((sv[0]*sv[0] -sv[1]*sv[1])
645 *(sv[1]*sv[1] -sv[2]*sv[2]))
646 / ((sv[0] + sv[2]) * sv[1]);
648 cosinusTheta = ( sv[1] * sv[1] + sv[0] * sv[2] ) / ((sv[0] + sv[2]) * sv[1]);
651 aRbp[0][0] = cosinusTheta; aRbp[0][1] = 0; aRbp[0][2] = -sinusTheta;
652 aRbp[1][0] = 0; aRbp[1][1] = 1; aRbp[1][2] = 0;
653 aRbp[2][0] = sinusTheta; aRbp[2][1] = 0; aRbp[2][2] = cosinusTheta;
658 for (i = 0; i < 3; i++) {
659 for (j = 0; j < 3; j++) {
661 for (k = 0; k < 3; k++) {
662 aRbint[i][j] += mU[i][k] * aRbp[k][j];
668 for (i = 0; i < 3; i++) {
669 for (j = 0; j < 3; j++) {
671 for (k = 0; k < 3; k++) {
672 aRb[i][j] += aRbint[i][k] * mV[j][k];
677 #ifdef DEBUG_Homographie
686 std::list<vpRotationMatrix> & vR,
687 std::list<vpTranslationVector> & vT,
688 std::list<vpColVector> & vN)
691 #ifdef DEBUG_Homographie
692 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
700 int cas1 =1, cas2=2, cas3=3, cas4=4;
702 bool norm1ok=
false, norm2ok =
false,norm3ok=
false,norm4ok =
false;
704 double tmp,determinantU,determinantV,s,distanceFictive;
705 vpMatrix mTempU(3,3),mTempV(3,3),U(3,3),V(3,3);
721 unsigned int vOrdre[3];
735 mTempU.
svd(svTemp, mTempV);
739 if (svTemp[0] >= svTemp[1]) {
740 if (svTemp[0] >= svTemp[2])
742 if (svTemp[1] > svTemp[2])
744 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
748 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
753 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
756 if (svTemp[1] >= svTemp[2]){
757 if (svTemp[0] > svTemp[2]) {
758 vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2;
760 vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0;
763 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
771 for (
unsigned int i = 0; i < 3; i++) {
772 sv[i] = svTemp[vOrdre[i]];
773 for (
unsigned int j = 0; j < 3; j++) {
774 U[i][j] = mTempU[i][vOrdre[j]];
775 V[i][j] = mTempV[i][vOrdre[j]];
779 #ifdef DEBUG_Homographie
780 printf(
"U : \n") ; Affiche(U) ;
781 printf(
"V : \n") ; affiche(V) ;
782 printf(
"Valeurs singulieres : ") ; affiche(sv);
786 determinantU = U[0][0] * (U[1][1]*U[2][2] - U[1][2]*U[2][1]) +
787 U[0][1] * (U[1][2]*U[2][0] - U[1][0]*U[2][2]) +
788 U[0][2] * (U[1][0]*U[2][1] - U[1][1]*U[2][0]);
790 determinantV = V[0][0] * (V[1][1]*V[2][2] - V[1][2]*V[2][1]) +
791 V[0][1] * (V[1][2]*V[2][0] - V[1][0]*V[2][2]) +
792 V[0][2] * (V[1][0]*V[2][1] - V[1][1]*V[2][0]);
794 s = determinantU * determinantV;
796 #ifdef DEBUG_Homographie
797 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
810 tmp = H[2][0]*x + H[2][1]*y + H[2][2] ;
812 if ((tmp/(sv[1] *s)) > 0)
813 distanceFictive = sv[1];
815 distanceFictive = -sv[1];
823 if ((sv[0] - sv[1]) < sing_threshold)
825 if ((sv[1] - sv[2]) < sing_threshold)
832 if ((sv[1] - sv[2]) < sing_threshold)
838 Nprim1 = 0.0; Nprim2 = 0.0; Nprim3 = 0.0; Nprim4 = 0.0;
857 Nprim1[0] = sqrt((sv[0] * sv[0] - sv[1] * sv[1] )/
858 (sv[0] * sv[0] - sv[2] * sv[2] ));
860 Nprim1[2] = sqrt((sv[1] * sv[1] - sv[2] * sv[2] )/
861 (sv[0] * sv[0] - sv[2] * sv[2] ));
863 Nprim2[0] = Nprim1[0]; Nprim2[2] = - Nprim1[2];
864 Nprim3[0] = - Nprim1[0]; Nprim3[2] = Nprim1[2];
865 Nprim4[0] = - Nprim1[0]; Nprim4[2] = - Nprim1[2];
893 tmp = N1[0] * x + N1[1] * y + N1[2];
894 tmp/= (distanceFictive *s);
898 tmp = N2[0] * x + N2[1] *y+ N2[2];
899 tmp/= (distanceFictive*s);
903 tmp = N3[0] * x + N3[1]*y+ N3[2];
904 tmp/= (distanceFictive*s);
908 tmp = N4[0] * x + N4[1] * y + N4[2];
909 tmp/= (distanceFictive*s);
916 tmp = N1[0] * x + N1[1] * y + N1[2];
917 tmp/= (distanceFictive*s);
921 tmp = N2[0] * x + N2[1] * y + N2[2];
922 tmp/= (distanceFictive*s);
929 tmp = N1[0] * x + N1[1] * y + N1[2];
930 tmp/= (distanceFictive*s);
934 tmp = N2[0] * x + N2[1] * y + N2[2];
935 tmp/= (distanceFictive*s);
943 if (distanceFictive>0)
951 Rprim1[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
952 ((sv[0] + sv[2]) * sv[1]);
954 Rprim1[2][2] = Rprim1[0][0];
959 / ((sv[0] + sv[2]) * sv[1]);
961 Rprim1[0][2] = -Rprim1[2][0];
965 Tprim1[0] = Nprim1[0];
967 Tprim1[2] = -Nprim1[2];
969 Tprim1*=(sv[0] - sv[2]);
977 Rprim2[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
978 ((sv[0] + sv[2]) * sv[1]);
980 Rprim2[2][2] = Rprim2[0][0];
985 / ((sv[0] + sv[2]) * sv[1]);
987 Rprim2[0][2] = -Rprim2[2][0];
991 Tprim2[0] = Nprim2[0];
993 Tprim2[2] = -Nprim2[2];
995 Tprim2*=(sv[0] - sv[2]);
1003 Rprim3[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
1004 ((sv[0] + sv[2]) * sv[1]);
1006 Rprim3[2][2] = Rprim3[0][0];
1011 / ((sv[0] + sv[2]) * sv[1]);
1013 Rprim3[0][2] = -Rprim3[2][0];
1017 Tprim3[0] = Nprim3[0];
1019 Tprim3[2] = -Nprim3[2];
1021 Tprim3*=(sv[0] - sv[2]);
1029 Rprim4[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2])/
1030 ((sv[0] + sv[2]) * sv[1]);
1032 Rprim4[2][2] = Rprim4[0][0];
1037 / ((sv[0] + sv[2]) * sv[1]);
1039 Rprim4[0][2] = -Rprim4[2][0];
1043 Tprim4[0] = Nprim4[0];
1045 Tprim4[2] = -Nprim4[2];
1047 Tprim4*=(sv[0] - sv[2]);
1061 Tprim1*= (sv[2] - sv[0]);
1069 Tprim2*= (sv[2] - sv[0]);
1079 Tprim1*= (sv[0] - sv[1]);
1087 Tprim2*= (sv[0] - sv[1]);
1098 if (distanceFictive <0)
1108 Rprim1[0][0] = ( sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1109 ((sv[0] - sv[2]) * sv[1]);
1111 Rprim1[2][2] = -Rprim1[0][0];
1116 / ((sv[0] - sv[2]) * sv[1]);
1118 Rprim1[0][2] = Rprim1[2][0];
1120 Rprim1[1][1] = -1.0;
1122 Tprim1[0] = Nprim1[0];
1124 Tprim1[2] = Nprim1[2];
1126 Tprim1*=(sv[0] + sv[2]);
1134 Rprim2[0][0] = (sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1135 ((sv[0] - sv[2]) * sv[1]);
1137 Rprim2[2][2] = -Rprim2[0][0];
1142 / ((sv[0] - sv[2]) * sv[1]);
1144 Rprim2[0][2] = Rprim2[2][0];
1146 Rprim2[1][1] = - 1.0;
1148 Tprim2[0] = Nprim2[0];
1150 Tprim2[2] = Nprim2[2];
1152 Tprim2*=(sv[0] + sv[2]);
1160 Rprim3[0][0] = ( sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1161 ((sv[0] - sv[2]) * sv[1]);
1163 Rprim3[2][2] = -Rprim3[0][0];
1168 / ((sv[0] - sv[2]) * sv[1]);
1170 Rprim3[0][2] = Rprim3[2][0];
1172 Rprim3[1][1] = -1.0;
1174 Tprim3[0] = Nprim3[0];
1176 Tprim3[2] = Nprim3[2];
1178 Tprim3*=(sv[0] + sv[2]);
1185 Rprim4[0][0] = ( sv[0] * sv[2]-
vpMath::sqr(sv[1]))/((sv[0] - sv[2]) * sv[1]);
1187 Rprim4[2][2] = -Rprim4[0][0];
1192 / ((sv[0] - sv[2]) * sv[1]);
1194 Rprim4[0][2] = Rprim4[2][0];
1196 Rprim4[1][1] = - 1.0;
1198 Tprim4[0] = Nprim4[0];
1200 Tprim4[2] = Nprim4[2];
1202 Tprim4*=(sv[0] + sv[2]);
1216 Tprim1*= (sv[2] + sv[0]);
1226 Tprim2*= (sv[2] + sv[0]);
1238 Tprim1*= (sv[2] + sv[0]);
1248 Tprim2*= (sv[0] + sv[2]);
1258 if ((distanceFictive>0) || (cas != cas4))
1264 R1 = s * U * Rprim1 * V.
t();
1266 T1 /= (distanceFictive *s);
1276 R2 = s * U * Rprim2 * V.
t();
1278 T2 /= (distanceFictive *s);
1288 R3 = s * U * Rprim3 * V.
t();
1290 T3 /= (distanceFictive *s);
1299 R4 = s * U * Rprim4 * V.
t();
1301 T4 /= (distanceFictive *s);
1312 std::cout <<
"On tombe dans le cas particulier ou le mouvement n'est pas estimable!" << std::endl;
1331 #ifdef DEBUG_Homographie
1332 printf(
"fin : Homographie_EstimationDeplacementCamera\n");
1335 #endif //#ifndef DOXYGEN_SHOULD_SKIP_THIS
1337 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1350 #ifdef DEBUG_Homographie
1351 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
1359 int cas1 =1, cas2=2, cas3=3, cas4=4;
1361 bool norm1ok=
false, norm2ok =
false,norm3ok=
false,norm4ok =
false;
1363 double tmp,determinantU,determinantV,s,distanceFictive;
1364 vpMatrix mTempU(3,3),mTempV(3,3),U(3,3),V(3,3);
1380 unsigned int vOrdre[3];
1394 mTempU.
svd(svTemp, mTempV);
1398 if (svTemp[0] >= svTemp[1]) {
1399 if (svTemp[0] >= svTemp[2])
1401 if (svTemp[1] > svTemp[2])
1403 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
1407 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
1412 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
1415 if (svTemp[1] >= svTemp[2]){
1416 if (svTemp[0] > svTemp[2]) {
1417 vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2;
1419 vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0;
1422 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
1430 for (
unsigned int i = 0; i < 3; i++) {
1431 sv[i] = svTemp[vOrdre[i]];
1432 for (
unsigned int j = 0; j < 3; j++) {
1433 U[i][j] = mTempU[i][vOrdre[j]];
1434 V[i][j] = mTempV[i][vOrdre[j]];
1438 #ifdef DEBUG_Homographie
1439 printf(
"U : \n") ; Affiche(U) ;
1440 printf(
"V : \n") ; affiche(V) ;
1441 printf(
"Valeurs singulieres : ") ; affiche(sv);
1445 determinantU = U[0][0] * (U[1][1]*U[2][2] - U[1][2]*U[2][1]) +
1446 U[0][1] * (U[1][2]*U[2][0] - U[1][0]*U[2][2]) +
1447 U[0][2] * (U[1][0]*U[2][1] - U[1][1]*U[2][0]);
1449 determinantV = V[0][0] * (V[1][1]*V[2][2] - V[1][2]*V[2][1]) +
1450 V[0][1] * (V[1][2]*V[2][0] - V[1][0]*V[2][2]) +
1451 V[0][2] * (V[1][0]*V[2][1] - V[1][1]*V[2][0]);
1453 s = determinantU * determinantV;
1455 #ifdef DEBUG_Homographie
1456 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
1469 tmp = H[2][0]*x + H[2][1]*y + H[2][2] ;
1471 if ((tmp/(sv[1] *s)) > 0)
1472 distanceFictive = sv[1];
1474 distanceFictive = -sv[1];
1482 if ((sv[0] - sv[1]) < sing_threshold)
1484 if ((sv[1] - sv[2]) < sing_threshold)
1491 if ((sv[1] - sv[2]) < sing_threshold)
1497 Nprim1 = 0.0; Nprim2 = 0.0; Nprim3 = 0.0; Nprim4 = 0.0;
1516 Nprim1[0] = sqrt((sv[0] * sv[0] - sv[1] * sv[1] )/
1517 (sv[0] * sv[0] - sv[2] * sv[2] ));
1519 Nprim1[2] = sqrt((sv[1] * sv[1] - sv[2] * sv[2] )/
1520 (sv[0] * sv[0] - sv[2] * sv[2] ));
1522 Nprim2[0] = Nprim1[0]; Nprim2[2] = - Nprim1[2];
1523 Nprim3[0] = - Nprim1[0]; Nprim3[2] = Nprim1[2];
1524 Nprim4[0] = - Nprim1[0]; Nprim4[2] = - Nprim1[2];
1552 tmp = N1[0] * x + N1[1] * y + N1[2];
1553 tmp/= (distanceFictive *s);
1557 tmp = N2[0] * x + N2[1] *y+ N2[2];
1558 tmp/= (distanceFictive*s);
1562 tmp = N3[0] * x + N3[1]*y+ N3[2];
1563 tmp/= (distanceFictive*s);
1567 tmp = N4[0] * x + N4[1] * y + N4[2];
1568 tmp/= (distanceFictive*s);
1575 tmp = N1[0] * x + N1[1] * y + N1[2];
1576 tmp/= (distanceFictive*s);
1580 tmp = N2[0] * x + N2[1] * y + N2[2];
1581 tmp/= (distanceFictive*s);
1588 tmp = N1[0] * x + N1[1] * y + N1[2];
1589 tmp/= (distanceFictive*s);
1593 tmp = N2[0] * x + N2[1] * y + N2[2];
1594 tmp/= (distanceFictive*s);
1602 if (distanceFictive>0)
1610 Rprim1[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
1611 ((sv[0] + sv[2]) * sv[1]);
1613 Rprim1[2][2] = Rprim1[0][0];
1618 / ((sv[0] + sv[2]) * sv[1]);
1620 Rprim1[0][2] = -Rprim1[2][0];
1624 Tprim1[0] = Nprim1[0];
1626 Tprim1[2] = -Nprim1[2];
1628 Tprim1*=(sv[0] - sv[2]);
1636 Rprim2[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
1637 ((sv[0] + sv[2]) * sv[1]);
1639 Rprim2[2][2] = Rprim2[0][0];
1644 / ((sv[0] + sv[2]) * sv[1]);
1646 Rprim2[0][2] = -Rprim2[2][0];
1650 Tprim2[0] = Nprim2[0];
1652 Tprim2[2] = -Nprim2[2];
1654 Tprim2*=(sv[0] - sv[2]);
1662 Rprim3[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
1663 ((sv[0] + sv[2]) * sv[1]);
1665 Rprim3[2][2] = Rprim3[0][0];
1670 / ((sv[0] + sv[2]) * sv[1]);
1672 Rprim3[0][2] = -Rprim3[2][0];
1676 Tprim3[0] = Nprim3[0];
1678 Tprim3[2] = -Nprim3[2];
1680 Tprim3*=(sv[0] - sv[2]);
1688 Rprim4[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2])/
1689 ((sv[0] + sv[2]) * sv[1]);
1691 Rprim4[2][2] = Rprim4[0][0];
1696 / ((sv[0] + sv[2]) * sv[1]);
1698 Rprim4[0][2] = -Rprim4[2][0];
1702 Tprim4[0] = Nprim4[0];
1704 Tprim4[2] = -Nprim4[2];
1706 Tprim4*=(sv[0] - sv[2]);
1720 Tprim1*= (sv[2] - sv[0]);
1728 Tprim2*= (sv[2] - sv[0]);
1738 Tprim1*= (sv[0] - sv[1]);
1746 Tprim2*= (sv[0] - sv[1]);
1757 if (distanceFictive <0)
1767 Rprim1[0][0] = ( sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1768 ((sv[0] - sv[2]) * sv[1]);
1770 Rprim1[2][2] = -Rprim1[0][0];
1775 / ((sv[0] - sv[2]) * sv[1]);
1777 Rprim1[0][2] = Rprim1[2][0];
1779 Rprim1[1][1] = -1.0;
1781 Tprim1[0] = Nprim1[0];
1783 Tprim1[2] = Nprim1[2];
1785 Tprim1*=(sv[0] + sv[2]);
1793 Rprim2[0][0] = (sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1794 ((sv[0] - sv[2]) * sv[1]);
1796 Rprim2[2][2] = -Rprim2[0][0];
1801 / ((sv[0] - sv[2]) * sv[1]);
1803 Rprim2[0][2] = Rprim2[2][0];
1805 Rprim2[1][1] = - 1.0;
1807 Tprim2[0] = Nprim2[0];
1809 Tprim2[2] = Nprim2[2];
1811 Tprim2*=(sv[0] + sv[2]);
1819 Rprim3[0][0] = ( sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1820 ((sv[0] - sv[2]) * sv[1]);
1822 Rprim3[2][2] = -Rprim3[0][0];
1827 / ((sv[0] - sv[2]) * sv[1]);
1829 Rprim3[0][2] = Rprim3[2][0];
1831 Rprim3[1][1] = -1.0;
1833 Tprim3[0] = Nprim3[0];
1835 Tprim3[2] = Nprim3[2];
1837 Tprim3*=(sv[0] + sv[2]);
1844 Rprim4[0][0] = ( sv[0] * sv[2]-
vpMath::sqr(sv[1]))/((sv[0] - sv[2]) * sv[1]);
1846 Rprim4[2][2] = -Rprim4[0][0];
1851 / ((sv[0] - sv[2]) * sv[1]);
1853 Rprim4[0][2] = Rprim4[2][0];
1855 Rprim4[1][1] = - 1.0;
1857 Tprim4[0] = Nprim4[0];
1859 Tprim4[2] = Nprim4[2];
1861 Tprim4*=(sv[0] + sv[2]);
1875 Tprim1*= (sv[2] + sv[0]);
1885 Tprim2*= (sv[2] + sv[0]);
1897 Tprim1*= (sv[2] + sv[0]);
1907 Tprim2*= (sv[0] + sv[2]);
1917 if ((distanceFictive>0) || (cas != cas4))
1923 R1 = s * U * Rprim1 * V.
t();
1925 T1 /= (distanceFictive *s);
1935 R2 = s * U * Rprim2 * V.
t();
1937 T2 /= (distanceFictive *s);
1947 R3 = s * U * Rprim3 * V.
t();
1949 T3 /= (distanceFictive *s);
1958 R4 = s * U * Rprim4 * V.
t();
1960 T4 /= (distanceFictive *s);
1971 std::cout <<
"On tombe dans le cas particulier ou le mouvement n'est pas estimable!" << std::endl;
1990 #ifdef DEBUG_Homographie
1991 printf(
"fin : Homographie_EstimationDeplacementCamera\n");
1995 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
Definition of the vpMatrix class.
Provide simple list management.
vpRotationMatrix t() const
transpose
void kill()
Destroy the list.
void setIdentity()
Basic initialisation (identity)
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
bool isARotationMatrix() const
test if the matrix is an rotation matrix
The vpRotationMatrix considers the particular case of a rotation matrix.
This class aims to compute the homography wrt.two images.
void svd(vpColVector &w, vpMatrix &v)
static double sqr(double x)
vpRowVector t() const
transpose of Vector
void addRight(const type &el)
add a new element in the list, at the right of the current one
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Class that consider the case of a translation vector.
void resize(const unsigned int i, const bool flagNullify=true)