42 #include <visp/vpHomography.h>
43 #include <visp/vpMath.h>
51 const double vpHomography::sing_threshold = 0.0001;
88 double distanceFictive;
89 double sinusTheta, cosinusTheta, signeSinus= 1;
90 double cosinusDesireeEstimee, cosinusAncien;
91 double s, determinantU, determinantV;
92 unsigned int i, j, k, w;
93 unsigned int vOrdre[3];
100 #ifdef DEBUG_Homographie
101 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
113 for (i=0 ; i < 3 ; i++)
114 for (j=0 ; j < 3 ; j++) mH[i][j] = aHb[i][j];
124 mTempU.
svd(svTemp,mTempV) ;
129 if (svTemp[0] >= svTemp[1]) {
130 if (svTemp[0] >= svTemp[2]) {
131 if (svTemp[1] > svTemp[2]) {
132 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
134 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
137 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
140 if (svTemp[1] >= svTemp[2]){
141 if (svTemp[0] > svTemp[2])
142 { vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2; }
144 { vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0; }
146 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
156 for (i = 0; i < 3; i++) {
157 sv[i] = svTemp[vOrdre[i]];
158 for (j = 0; j < 3; j++) {
159 mU[i][j] = mTempU[i][vOrdre[j]];
160 mV[i][j] = mTempV[i][vOrdre[j]];
164 #ifdef DEBUG_Homographie
165 printf(
"U : \n") ; std::cout << mU << std::endl ;
166 printf(
"V : \n") ; std::cout << mV << std::endl ;
167 printf(
"Valeurs singulieres : ") ; std::cout << sv.
t() ;
171 determinantV = mV.
det();
172 determinantU = mU.
det();
174 s = determinantU * determinantV;
176 #ifdef DEBUG_Homographie
177 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
183 distanceFictive = sv[1];
184 #ifdef DEBUG_Homographie
185 printf (
"d = %f\n",distanceFictive);
189 if (((sv[0] - sv[1]) < sing_threshold) && (sv[0] - sv[2]) < sing_threshold)
203 n[0] = normaleDesiree[0];
204 n[1] = normaleDesiree[1];
205 n[2] = normaleDesiree[2];
209 #ifdef DEBUG_Homographie
210 printf(
"\nCas general\n");
224 mX[0][0] = sqrt ((sv[0] * sv[0] - sv[1] * sv[1])
225 / (sv[0] * sv[0] - sv[2] * sv[2]));
227 mX[2][0] = sqrt ((sv[1] * sv[1] - sv[2] * sv[2])
228 / (sv[0] * sv[0] - sv[2] * sv[2]));
230 mX[0][1] = -mX[0][0];
236 for (w = 0; w < 2; w++) {
237 for (k = 0; k < 2; k++) {
240 for (i = 0; i < 3; i++) {
241 normaleEstimee[i] = 0.0;
242 for (j = 0; j < 3; j++) {
243 normaleEstimee[i] += (2.0 * k - 1.0) * mV[i][j] * mX[j][w];
249 cosinusDesireeEstimee = 0.0;
250 for (i = 0; i < 3; i++)
251 cosinusDesireeEstimee += normaleEstimee[i] * normaleDesiree[i];
257 if (cosinusDesireeEstimee > cosinusAncien)
259 cosinusAncien = cosinusDesireeEstimee;
262 for (j = 0; j < 3; j++)
263 n[j] = normaleEstimee[j];
266 aTbp[0] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[0][w];
267 aTbp[1] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[1][w];
268 aTbp[2] = -(2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[2][w];
282 for (i = 0; i < 3; i++) {
284 for (j = 0; j < 3; j++) {
285 atb[i] += mU[i][j] * aTbp[j];
287 atb[i] /= distanceFictive;
291 #ifdef DEBUG_Homographie
292 printf(
"t' : ") ; std::cout << aTbp.t() ;
293 printf(
"t/d : ") ; std::cout << atb.
t() ;
294 printf(
"n : ") ; std::cout << n.
t() ;
305 sinusTheta = signeSinus*sqrt((sv[0]*sv[0] -sv[1]*sv[1])
306 *(sv[1]*sv[1] -sv[2]*sv[2]))
307 / ((sv[0] + sv[2]) * sv[1]);
309 cosinusTheta = ( sv[1] * sv[1] + sv[0] * sv[2] ) / ((sv[0] + sv[2]) * sv[1]);
312 aRbp[0][0] = cosinusTheta; aRbp[0][1] = 0; aRbp[0][2] = -sinusTheta;
313 aRbp[1][0] = 0; aRbp[1][1] = 1; aRbp[1][2] = 0;
314 aRbp[2][0] = sinusTheta; aRbp[2][1] = 0; aRbp[2][2] = cosinusTheta;
319 for (i = 0; i < 3; i++) {
320 for (j = 0; j < 3; j++) {
322 for (k = 0; k < 3; k++) {
323 aRbint[i][j] += mU[i][k] * aRbp[k][j];
329 for (i = 0; i < 3; i++) {
330 for (j = 0; j < 3; j++) {
332 for (k = 0; k < 3; k++) {
333 aRb[i][j] += aRbint[i][k] * mV[j][k];
338 #ifdef DEBUG_Homographie
403 double distanceFictive;
404 double sinusTheta, cosinusTheta, signeSinus= 1;
405 double cosinusDesireeEstimee, cosinusAncien;
406 double s, determinantU, determinantV;
407 unsigned int i, j, k, w;
408 unsigned int vOrdre[3];
411 normaleDesiree[0]=0;normaleDesiree[1]=0;normaleDesiree[2]=1;
414 #ifdef DEBUG_Homographie
415 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
427 for (i=0 ; i < 3 ; i++)
428 for (j=0 ; j < 3 ; j++) mH[i][j] = aHb[i][j];
438 mTempU.
svd(svTemp,mTempV) ;
443 if (svTemp[0] >= svTemp[1]) {
444 if (svTemp[0] >= svTemp[2]) {
445 if (svTemp[1] > svTemp[2]) {
446 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
448 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
451 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
454 if (svTemp[1] >= svTemp[2]){
455 if (svTemp[0] > svTemp[2])
456 { vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2; }
458 { vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0; }
460 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
470 for (i = 0; i < 3; i++) {
471 sv[i] = svTemp[vOrdre[i]];
472 for (j = 0; j < 3; j++) {
473 mU[i][j] = mTempU[i][vOrdre[j]];
474 mV[i][j] = mTempV[i][vOrdre[j]];
478 #ifdef DEBUG_Homographie
479 printf(
"U : \n") ; std::cout << mU << std::endl ;
480 printf(
"V : \n") ; std::cout << mV << std::endl ;
481 printf(
"Valeurs singulieres : ") ; std::cout << sv.
t() ;
485 determinantV = mV.
det();
486 determinantU = mU.
det();
488 s = determinantU * determinantV;
490 #ifdef DEBUG_Homographie
491 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
497 distanceFictive = sv[1];
498 #ifdef DEBUG_Homographie
499 printf (
"d = %f\n",distanceFictive);
503 if (((sv[0] - sv[1]) < sing_threshold) && (sv[0] - sv[2]) < sing_threshold)
517 n[0] = normaleDesiree[0];
518 n[1] = normaleDesiree[1];
519 n[2] = normaleDesiree[2];
523 #ifdef DEBUG_Homographie
524 printf(
"\nCas general\n");
538 mX[0][0] = sqrt ((sv[0] * sv[0] - sv[1] * sv[1])
539 / (sv[0] * sv[0] - sv[2] * sv[2]));
541 mX[2][0] = sqrt ((sv[1] * sv[1] - sv[2] * sv[2])
542 / (sv[0] * sv[0] - sv[2] * sv[2]));
544 mX[0][1] = -mX[0][0];
550 for (w = 0; w < 2; w++) {
551 for (k = 0; k < 2; k++) {
554 for (i = 0; i < 3; i++) {
555 normaleEstimee[i] = 0.0;
556 for (j = 0; j < 3; j++) {
557 normaleEstimee[i] += (2.0 * k - 1.0) * mV[i][j] * mX[j][w];
563 cosinusDesireeEstimee = 0.0;
564 for (i = 0; i < 3; i++)
565 cosinusDesireeEstimee += normaleEstimee[i] * normaleDesiree[i];
571 if (cosinusDesireeEstimee > cosinusAncien)
573 cosinusAncien = cosinusDesireeEstimee;
576 for (j = 0; j < 3; j++)
577 n[j] = normaleEstimee[j];
580 aTbp[0] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[0][w];
581 aTbp[1] = (2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[1][w];
582 aTbp[2] = -(2.0 * k - 1.0) * (sv[0] - sv[2]) * mX[2][w];
596 for (i = 0; i < 3; i++) {
598 for (j = 0; j < 3; j++) {
599 atb[i] += mU[i][j] * aTbp[j];
601 atb[i] /= distanceFictive;
605 #ifdef DEBUG_Homographie
606 printf(
"t' : ") ; std::cout << aTbp.t() ;
607 printf(
"t/d : ") ; std::cout << atb.
t() ;
608 printf(
"n : ") ; std::cout << n.
t() ;
619 sinusTheta = signeSinus*sqrt((sv[0]*sv[0] -sv[1]*sv[1])
620 *(sv[1]*sv[1] -sv[2]*sv[2]))
621 / ((sv[0] + sv[2]) * sv[1]);
623 cosinusTheta = ( sv[1] * sv[1] + sv[0] * sv[2] ) / ((sv[0] + sv[2]) * sv[1]);
626 aRbp[0][0] = cosinusTheta; aRbp[0][1] = 0; aRbp[0][2] = -sinusTheta;
627 aRbp[1][0] = 0; aRbp[1][1] = 1; aRbp[1][2] = 0;
628 aRbp[2][0] = sinusTheta; aRbp[2][1] = 0; aRbp[2][2] = cosinusTheta;
633 for (i = 0; i < 3; i++) {
634 for (j = 0; j < 3; j++) {
636 for (k = 0; k < 3; k++) {
637 aRbint[i][j] += mU[i][k] * aRbp[k][j];
643 for (i = 0; i < 3; i++) {
644 for (j = 0; j < 3; j++) {
646 for (k = 0; k < 3; k++) {
647 aRb[i][j] += aRbint[i][k] * mV[j][k];
652 #ifdef DEBUG_Homographie
678 nd[0]=0;nd[1]=0;nd[2]=1;
687 std::list<vpRotationMatrix> & vR,
688 std::list<vpTranslationVector> & vT,
689 std::list<vpColVector> & vN)
692 #ifdef DEBUG_Homographie
693 printf (
"debut : Homographie_EstimationDeplacementCamera\n");
701 int cas1 =1, cas2=2, cas3=3, cas4=4;
703 bool norm1ok=
false, norm2ok =
false,norm3ok=
false,norm4ok =
false;
705 double tmp,determinantU,determinantV,s,distanceFictive;
706 vpMatrix mTempU(3,3),mTempV(3,3),U(3,3),V(3,3);
722 unsigned int vOrdre[3];
736 mTempU.
svd(svTemp, mTempV);
740 if (svTemp[0] >= svTemp[1]) {
741 if (svTemp[0] >= svTemp[2])
743 if (svTemp[1] > svTemp[2])
745 vOrdre[0] = 0; vOrdre[1] = 1; vOrdre[2] = 2;
749 vOrdre[0] = 0; vOrdre[1] = 2; vOrdre[2] = 1;
754 vOrdre[0] = 2; vOrdre[1] = 0; vOrdre[2] = 1;
757 if (svTemp[1] >= svTemp[2]){
758 if (svTemp[0] > svTemp[2]) {
759 vOrdre[0] = 1; vOrdre[1] = 0; vOrdre[2] = 2;
761 vOrdre[0] = 1; vOrdre[1] = 2; vOrdre[2] = 0;
764 vOrdre[0] = 2; vOrdre[1] = 1; vOrdre[2] = 0;
772 for (
unsigned int i = 0; i < 3; i++) {
773 sv[i] = svTemp[vOrdre[i]];
774 for (
unsigned int j = 0; j < 3; j++) {
775 U[i][j] = mTempU[i][vOrdre[j]];
776 V[i][j] = mTempV[i][vOrdre[j]];
780 #ifdef DEBUG_Homographie
781 printf(
"U : \n") ; Affiche(U) ;
782 printf(
"V : \n") ; affiche(V) ;
783 printf(
"Valeurs singulieres : ") ; affiche(sv);
787 determinantU = U[0][0] * (U[1][1]*U[2][2] - U[1][2]*U[2][1]) +
788 U[0][1] * (U[1][2]*U[2][0] - U[1][0]*U[2][2]) +
789 U[0][2] * (U[1][0]*U[2][1] - U[1][1]*U[2][0]);
791 determinantV = V[0][0] * (V[1][1]*V[2][2] - V[1][2]*V[2][1]) +
792 V[0][1] * (V[1][2]*V[2][0] - V[1][0]*V[2][2]) +
793 V[0][2] * (V[1][0]*V[2][1] - V[1][1]*V[2][0]);
795 s = determinantU * determinantV;
797 #ifdef DEBUG_Homographie
798 printf (
"s = det(U) * det(V) = %f * %f = %f\n",determinantU,determinantV,s);
811 tmp = H[2][0]*x + H[2][1]*y + H[2][2] ;
813 if ((tmp/(sv[1] *s)) > 0)
814 distanceFictive = sv[1];
816 distanceFictive = -sv[1];
824 if ((sv[0] - sv[1]) < sing_threshold)
826 if ((sv[1] - sv[2]) < sing_threshold)
833 if ((sv[1] - sv[2]) < sing_threshold)
839 Nprim1 = 0.0; Nprim2 = 0.0; Nprim3 = 0.0; Nprim4 = 0.0;
858 Nprim1[0] = sqrt((sv[0] * sv[0] - sv[1] * sv[1] )/
859 (sv[0] * sv[0] - sv[2] * sv[2] ));
861 Nprim1[2] = sqrt((sv[1] * sv[1] - sv[2] * sv[2] )/
862 (sv[0] * sv[0] - sv[2] * sv[2] ));
864 Nprim2[0] = Nprim1[0]; Nprim2[2] = - Nprim1[2];
865 Nprim3[0] = - Nprim1[0]; Nprim3[2] = Nprim1[2];
866 Nprim4[0] = - Nprim1[0]; Nprim4[2] = - Nprim1[2];
894 tmp = N1[0] * x + N1[1] * y + N1[2];
895 tmp/= (distanceFictive *s);
899 tmp = N2[0] * x + N2[1] *y+ N2[2];
900 tmp/= (distanceFictive*s);
904 tmp = N3[0] * x + N3[1]*y+ N3[2];
905 tmp/= (distanceFictive*s);
909 tmp = N4[0] * x + N4[1] * y + N4[2];
910 tmp/= (distanceFictive*s);
917 tmp = N1[0] * x + N1[1] * y + N1[2];
918 tmp/= (distanceFictive*s);
922 tmp = N2[0] * x + N2[1] * y + N2[2];
923 tmp/= (distanceFictive*s);
930 tmp = N1[0] * x + N1[1] * y + N1[2];
931 tmp/= (distanceFictive*s);
935 tmp = N2[0] * x + N2[1] * y + N2[2];
936 tmp/= (distanceFictive*s);
944 if (distanceFictive>0)
952 Rprim1[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
953 ((sv[0] + sv[2]) * sv[1]);
955 Rprim1[2][2] = Rprim1[0][0];
960 / ((sv[0] + sv[2]) * sv[1]);
962 Rprim1[0][2] = -Rprim1[2][0];
966 Tprim1[0] = Nprim1[0];
968 Tprim1[2] = -Nprim1[2];
970 Tprim1*=(sv[0] - sv[2]);
978 Rprim2[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
979 ((sv[0] + sv[2]) * sv[1]);
981 Rprim2[2][2] = Rprim2[0][0];
986 / ((sv[0] + sv[2]) * sv[1]);
988 Rprim2[0][2] = -Rprim2[2][0];
992 Tprim2[0] = Nprim2[0];
994 Tprim2[2] = -Nprim2[2];
996 Tprim2*=(sv[0] - sv[2]);
1004 Rprim3[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2]) /
1005 ((sv[0] + sv[2]) * sv[1]);
1007 Rprim3[2][2] = Rprim3[0][0];
1012 / ((sv[0] + sv[2]) * sv[1]);
1014 Rprim3[0][2] = -Rprim3[2][0];
1018 Tprim3[0] = Nprim3[0];
1020 Tprim3[2] = -Nprim3[2];
1022 Tprim3*=(sv[0] - sv[2]);
1030 Rprim4[0][0] = (
vpMath::sqr(sv[1]) + sv[0] * sv[2])/
1031 ((sv[0] + sv[2]) * sv[1]);
1033 Rprim4[2][2] = Rprim4[0][0];
1038 / ((sv[0] + sv[2]) * sv[1]);
1040 Rprim4[0][2] = -Rprim4[2][0];
1044 Tprim4[0] = Nprim4[0];
1046 Tprim4[2] = -Nprim4[2];
1048 Tprim4*=(sv[0] - sv[2]);
1062 Tprim1*= (sv[2] - sv[0]);
1070 Tprim2*= (sv[2] - sv[0]);
1080 Tprim1*= (sv[0] - sv[1]);
1088 Tprim2*= (sv[0] - sv[1]);
1099 if (distanceFictive <0)
1109 Rprim1[0][0] = ( sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1110 ((sv[0] - sv[2]) * sv[1]);
1112 Rprim1[2][2] = -Rprim1[0][0];
1117 / ((sv[0] - sv[2]) * sv[1]);
1119 Rprim1[0][2] = Rprim1[2][0];
1121 Rprim1[1][1] = -1.0;
1123 Tprim1[0] = Nprim1[0];
1125 Tprim1[2] = Nprim1[2];
1127 Tprim1*=(sv[0] + sv[2]);
1135 Rprim2[0][0] = (sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1136 ((sv[0] - sv[2]) * sv[1]);
1138 Rprim2[2][2] = -Rprim2[0][0];
1143 / ((sv[0] - sv[2]) * sv[1]);
1145 Rprim2[0][2] = Rprim2[2][0];
1147 Rprim2[1][1] = - 1.0;
1149 Tprim2[0] = Nprim2[0];
1151 Tprim2[2] = Nprim2[2];
1153 Tprim2*=(sv[0] + sv[2]);
1161 Rprim3[0][0] = ( sv[0] * sv[2] -
vpMath::sqr(sv[1])) /
1162 ((sv[0] - sv[2]) * sv[1]);
1164 Rprim3[2][2] = -Rprim3[0][0];
1169 / ((sv[0] - sv[2]) * sv[1]);
1171 Rprim3[0][2] = Rprim3[2][0];
1173 Rprim3[1][1] = -1.0;
1175 Tprim3[0] = Nprim3[0];
1177 Tprim3[2] = Nprim3[2];
1179 Tprim3*=(sv[0] + sv[2]);
1186 Rprim4[0][0] = ( sv[0] * sv[2]-
vpMath::sqr(sv[1]))/((sv[0] - sv[2]) * sv[1]);
1188 Rprim4[2][2] = -Rprim4[0][0];
1193 / ((sv[0] - sv[2]) * sv[1]);
1195 Rprim4[0][2] = Rprim4[2][0];
1197 Rprim4[1][1] = - 1.0;
1199 Tprim4[0] = Nprim4[0];
1201 Tprim4[2] = Nprim4[2];
1203 Tprim4*=(sv[0] + sv[2]);
1217 Tprim1*= (sv[2] + sv[0]);
1227 Tprim2*= (sv[2] + sv[0]);
1239 Tprim1*= (sv[2] + sv[0]);
1249 Tprim2*= (sv[0] + sv[2]);
1259 if ((distanceFictive>0) || (cas != cas4))
1265 R1 = s * U * Rprim1 * V.
t();
1267 T1 /= (distanceFictive *s);
1277 R2 = s * U * Rprim2 * V.
t();
1279 T2 /= (distanceFictive *s);
1289 R3 = s * U * Rprim3 * V.
t();
1291 T3 /= (distanceFictive *s);
1300 R4 = s * U * Rprim4 * V.
t();
1302 T4 /= (distanceFictive *s);
1313 std::cout <<
"On tombe dans le cas particulier ou le mouvement n'est pas estimable!" << std::endl;
1332 #ifdef DEBUG_Homographie
1333 printf(
"fin : Homographie_EstimationDeplacementCamera\n");
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
double det(vpDetMethod method=LU_DECOMPOSITION) const
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)