45 #include <visp3/core/vpDebug.h>
46 #include <visp3/vision/vpPose.h>
47 #include <visp3/core/vpExponentialMap.h>
48 #include <visp3/core/vpPixelMeterConversion.h>
49 #include <visp3/core/vpRobust.h>
50 #include <visp3/core/vpMatrixException.h>
51 #include <visp3/core/vpMath.h>
52 #include <visp3/core/vpException.h>
53 #include <visp3/core/vpTrackingException.h>
54 #include <visp3/mbt/vpMbEdgeTracker.h>
55 #include <visp3/mbt/vpMbtDistanceLine.h>
56 #include <visp3/mbt/vpMbtXmlParser.h>
57 #include <visp3/core/vpPolygon3D.h>
58 #include <visp3/core/vpVelocityTwistMatrix.h>
71 : compute_interaction(1), lambda(1), me(), lines(1), circles(1), cylinders(1), nline(0), ncircle(0), ncylinder(0),
72 nbvisiblepolygone(0), percentageGdPt(0.4), scales(1),
73 Ipyramid(0), scaleLevel(0), nbFeaturesForProjErrorComputation(0)
94 for (
unsigned int i = 0; i <
scales.size(); i += 1){
96 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
104 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
116 for (
unsigned int i = 0; i <
circles.size(); i += 1){
117 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
139 for (
unsigned int i = 0; i <
scales.size(); i += 1){
141 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
146 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
151 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
171 double residu_1 = 1e3;
179 unsigned int iter = 0;
182 unsigned int nbrow = 0;
183 unsigned int nberrors_lines = 0;
184 unsigned int nberrors_cylinders = 0;
185 unsigned int nberrors_circles = 0;
187 nbrow =
initMbtTracking(nberrors_lines, nberrors_cylinders, nberrors_circles);
207 while ( reloop ==
true && iter<10)
211 weighted_error.
resize(nerror);
224 count = count / (double)nbrow;
239 vpRobust robust_lines(nberrors_lines);
240 vpRobust robust_cylinders(nberrors_cylinders);
241 vpRobust robust_circles(nberrors_circles);
263 while(std::fabs((residu_1 - r)*1e8) > std::numeric_limits<double>::epsilon() && (iter<30))
267 bool reStartFromLastIncrement =
false;
271 if(!reStartFromLastIncrement){
273 w_lines, w_cylinders, w_circles, error_lines, error_cylinders, error_circles, nberrors_lines, nberrors_cylinders,
277 weighted_error, mu, m_error_prev, m_w_prev, cMoPrev, residu_1, r);
314 double e_prev = 0, e_cur, e_next;
316 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
317 if((*it)->isTracked())
326 int index = *itindex;
340 std::list<vpMeSite>::const_iterator itListLine;
342 unsigned int indexFeature = 0;
344 for(
unsigned int a = 0 ; a < l->
meline.size() ; a++)
346 if (iter == 0 && l->
meline[a] != NULL)
347 itListLine = l->
meline[a]->getMeList().begin();
349 for (
unsigned int i=0 ; i < l->
nbFeature[a] ; i++)
351 for (
unsigned int j=0; j < 6 ; j++)
353 L[n+i][j] = l->
L[indexFeature][j];
355 error[n+i] = l->
error[indexFeature];
357 if (error[n+i] <= limite) count = count+1.0;
370 if (indexFeature == 0)
375 e_next = l->
error[1];
388 e_cur = l->
error[indexFeature];
397 e_cur = l->
error[indexFeature];
398 e_next = l->
error[indexFeature+1];
399 if ( fabs(e_cur - e_prev) < limite )
403 if ( fabs(e_cur - e_next) < limite )
416 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it) {
417 if((*it)->isTracked())
423 std::list<vpMeSite>::const_iterator itCyl1;
424 std::list<vpMeSite>::const_iterator itCyl2;
426 itCyl1 = cy->
meline1->getMeList().begin();
427 itCyl2 = cy->
meline2->getMeList().begin();
430 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
431 for(
unsigned int j=0; j < 6 ; j++){
432 L[n+i][j] = cy->
L[i][j];
434 error[n+i] = cy->
error[i];
436 if (error[n+i] <= limite) count = count+1.0;
444 if(i<cy->nbFeaturel1) {
458 e_cur = cy->
error[0];
461 e_next = cy->
error[1];
472 e_cur = cy->
error[i];
475 e_next = cy->
error[i+1];
488 e_cur = cy->
error[i];
497 e_cur = cy->
error[i];
506 e_cur = cy->
error[i];
507 e_next = cy->
error[i+1];
508 if ( fabs(e_cur - e_prev) < limite ){
511 if ( fabs(e_cur - e_next) < limite ){
522 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[lvl].begin(); it!=
circles[lvl].end(); ++it) {
523 if((*it)->isTracked())
529 std::list<vpMeSite>::const_iterator itCir;
530 if (iter == 0 && (ci->
meEllipse != NULL)) {
531 itCir = ci->
meEllipse->getMeList().begin();
534 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
535 for(
unsigned int j=0; j < 6 ; j++){
536 L[n+i][j] = ci->
L[i][j];
538 error[n+i] = ci->
error[i];
540 if (error[n+i] <= limite) count = count+1.0;
555 e_cur = ci->
error[0];
558 e_next = ci->
error[1];
571 e_cur = ci->
error[i];
580 e_cur = ci->
error[i];
581 e_next = ci->
error[i+1];
582 if ( fabs(e_cur - e_prev) < limite ){
585 if ( fabs(e_cur - e_next) < limite ){
604 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
605 if((*it)->isTracked()){
611 int index = *itindex;
622 unsigned int indexFeature = 0;
623 for(
unsigned int a = 0 ; a < l->
meline.size(); a++){
624 std::list<vpMeSite>::const_iterator itListLine;
627 itListLine = l->
meline[a]->getMeList().begin();
629 for (
unsigned int i=0 ; i < l->
nbFeature[a] ; i++){
642 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
643 if((*it)->isTracked()){
647 std::list<vpMeSite>::const_iterator itCyl1;
648 std::list<vpMeSite>::const_iterator itCyl2;
650 itCyl1 = cy->
meline1->getMeList().begin();
651 itCyl2 = cy->
meline2->getMeList().begin();
654 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
657 if(i<cy->nbFeaturel1) {
672 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[lvl].begin(); it!=
circles[lvl].end(); ++it){
673 if((*it)->isTracked()){
677 std::list<vpMeSite>::const_iterator itCir;
679 itCir = ci->
meEllipse->getMeList().begin();
682 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
700 for (
unsigned int i = 0; i < nerror; i++) {
701 wi =
m_w[i]*factor[i];
704 weighted_error[i] = wi*eri;
706 for (
unsigned int j = 0; j < 6; j++) {
707 L[i][j] = wi*L[i][j];
711 for(
unsigned int i = 0; i < nerror; i++) {
712 wi =
m_w[i]*factor[i];
715 weighted_error[i] = wi*eri;
724 if (isoJoIdentity_) {
728 unsigned int rank = (L*cVo).kernel(K);
737 isoJoIdentity_ =
false;
771 unsigned int nlines = 0;
772 unsigned int ncylinders = 0;
773 unsigned int ncircles = 0;
775 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
776 if((*it)->isTracked()){
780 for (
unsigned int j=0; j < 6 ; j++){
781 L[n+i][j] = l->
L[i][j];
782 error[n+i] = l->
error[i];
783 error_lines[nlines+i] = error[n+i];
791 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
792 if((*it)->isTracked()){
795 for(
unsigned int i=0 ; i < cy->
nbFeature ; i++){
796 for(
unsigned int j=0; j < 6 ; j++){
797 L[n+i][j] = cy->
L[i][j];
798 error[n+i] = cy->
error[i];
799 error_cylinders[ncylinders+i] = error[n+i];
808 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[lvl].begin(); it!=
circles[lvl].end(); ++it){
809 if((*it)->isTracked()){
812 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
813 for(
unsigned int j=0; j < 6 ; j++){
814 L[n+i][j] = ci->
L[i][j];
815 error[n+i] = ci->
error[i];
816 error_circles[ncircles+i] = error[n+i];
829 double &mu,
bool &reStartFromLastIncrement) {
840 reStartFromLastIncrement =
true;
866 LVJ_true = (L*cVo*
oJo);
871 for (
unsigned int i = 0; i < nerror; i++) {
872 wi =
m_w[i]*factor[i];
878 weighted_error[i] = wi*eri ;
880 for (
unsigned int j = 0; j < 6; j++) {
881 L[i][j] = wi*L[i][j];
885 for(
unsigned int i = 0; i < nerror; i++) {
886 wi =
m_w[i]*factor[i];
892 weighted_error[i] = wi*eri ;
933 vpMatrix LTLmuI = LVJTLVJ + (LMA*mu);
963 const unsigned int nbrow,
vpColVector &weighted_error,
967 const unsigned int nberrors_lines,
const unsigned int nberrors_cylinders,
const unsigned int nberrors_circles) {
970 weighted_error.
resize(nerror);
973 w_lines.
resize(nberrors_lines);
975 w_cylinders.
resize(nberrors_cylinders);
977 w_circles.
resize(nberrors_circles);
983 if(nberrors_lines > 0)
985 if(nberrors_cylinders > 0)
987 if(nberrors_circles > 0)
995 if(nberrors_lines > 0)
997 if(nberrors_cylinders > 0)
999 if(nberrors_circles > 0)
1003 unsigned int cpt = 0;
1005 if(cpt<nberrors_lines){
1006 m_w[cpt] = w_lines[cpt];
1008 else if (cpt<nberrors_lines+nberrors_cylinders){
1009 m_w[cpt] = w_cylinders[cpt-nberrors_lines];
1012 m_w[cpt] = w_circles[cpt-nberrors_lines-nberrors_cylinders];
1029 unsigned int nbFeatures = 0;
1034 for(
unsigned int a = 0 ; a < l->
meline.size() ; a++){
1035 if(l->
meline[a] != NULL){
1036 double lineNormGradient;
1037 unsigned int lineNbFeatures;
1038 l->
meline[a]->computeProjectionError(_I, lineNormGradient, lineNbFeatures);
1040 nbFeatures += lineNbFeatures;
1052 double cylinderNormGradient = 0;
1053 unsigned int cylinderNbFeatures = 0;
1054 cy->
meline1->computeProjectionError(_I, cylinderNormGradient, cylinderNbFeatures);
1056 nbFeatures += cylinderNbFeatures;
1061 double cylinderNormGradient = 0;
1062 unsigned int cylinderNbFeatures = 0;
1063 cy->
meline2->computeProjectionError(_I, cylinderNormGradient, cylinderNbFeatures);
1065 nbFeatures += cylinderNbFeatures;
1074 double circleNormGradient = 0;
1075 unsigned int circleNbFeatures = 0;
1076 c->
meEllipse->computeProjectionError(_I, circleNormGradient, circleNbFeatures);
1078 nbFeatures += circleNbFeatures;
1082 if(nbFeatures > 0) {
1101 int nbExpectedPoint = 0;
1102 int nbGoodPoint = 0;
1109 for(
unsigned int a = 0 ; a < l->
meline.size() ; a++){
1110 if(l->
meline[a] != NULL){
1111 nbExpectedPoint += (int)l->
meline[a]->expecteddensity;
1112 for(std::list<vpMeSite>::const_iterator itme=l->
meline[a]->getMeList().begin(); itme!=l->
meline[a]->getMeList().end(); ++itme){
1126 nbExpectedPoint += (int)cy->
meline1->expecteddensity;
1127 for(std::list<vpMeSite>::const_iterator itme1=cy->
meline1->getMeList().begin(); itme1!=cy->
meline1->getMeList().end(); ++itme1){
1132 nbExpectedPoint += (int)cy->
meline2->expecteddensity;
1133 for(std::list<vpMeSite>::const_iterator itme2=cy->
meline2->getMeList().begin(); itme2!=cy->
meline2->getMeList().end(); ++itme2){
1145 nbExpectedPoint += ci->
meEllipse->getExpectedDensity();
1146 for(std::list<vpMeSite>::const_iterator itme=ci->
meEllipse->getMeList().begin(); itme!=ci->
meEllipse->getMeList().end(); ++itme){
1158 if (nbGoodPoint < nb_min || nbExpectedPoint < 2) {
1159 std::ostringstream oss;
1160 oss <<
"Not enough moving edges ("
1162 <<
") to track the object: expected "
1164 <<
". Try to reduce the threshold="
1166 <<
" using vpMbTracker::setGoodMovingEdgesRatioThreshold()";
1184 unsigned int lvl = (
unsigned int)
scales.size();
1202 vpTRACE(
"Error in moving edge tracking") ;
1257 bool newvisibleface = false ;
1315 #ifdef VISP_HAVE_OGRE
1334 unsigned int i = (
unsigned int)
scales.size();
1442 #ifdef VISP_HAVE_XML2
1451 std::cout <<
" *********** Parsing XML for Mb Edge Tracker ************ " << std::endl;
1452 xmlp.
parse(configFile);
1461 xmlp.
getMe(meParser);
1490 vpTRACE(
"You need the libXML2 to read the config file %s", configFile);
1508 const unsigned int thickness,
const bool displayFullModel)
1510 for (
unsigned int i = 0; i <
scales.size(); i += 1){
1513 (*it)->display(I,cMo_, camera, col, thickness, displayFullModel);
1517 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1521 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1528 #ifdef VISP_HAVE_OGRE
1547 const unsigned int thickness,
const bool displayFullModel)
1549 for (
unsigned int i = 0; i <
scales.size(); i += 1){
1552 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel) ;
1556 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel) ;
1560 (*it)->display(I, cMo_, camera, col, thickness, displayFullModel);
1566 #ifdef VISP_HAVE_OGRE
1576 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[lvl].begin(); it!=
lines[lvl].end(); ++it){
1583 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[lvl].begin(); it!=
cylinders[lvl].end(); ++it){
1590 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[lvl].begin(); it!=
circles[lvl].end(); ++it){
1614 bool isvisible = false ;
1617 int index = *itindex;
1618 if (index ==-1) isvisible =true ;
1638 for(
unsigned int a = 0 ; a < l->
meline.size() ; a++){
1651 bool isvisible = false ;
1654 if (index ==-1) isvisible =true ;
1689 bool isvisible = false ;
1692 if (index ==-1) isvisible =true ;
1729 if(l->
meline.size() == 0){
1768 if((*it)->isTracked()){
1779 if((*it)->isTracked()){
1790 if((*it)->isTracked()){
1806 if((*it)->isTracked()){
1808 unsigned int indexLine = 0;
1810 for(
unsigned int a = 0 ; a < l->
meline.size() ; a++)
1813 std::list<vpMeSite>::iterator itListLine;
1814 itListLine = l->
meline[a]->getMeList().begin();
1816 for (
unsigned int i=0 ; i < l->
nbFeature[a] ; i++){
1817 wmean +=
m_w[n+indexLine] ;
1819 if (
m_w[n+indexLine] < 0.5){
1847 if((*it)->isTracked()){
1850 std::list<vpMeSite>::iterator itListCyl1;
1851 std::list<vpMeSite>::iterator itListCyl2;
1854 itListCyl1 = cy->
meline1->getMeList().begin();
1855 itListCyl2 = cy->
meline2->getMeList().begin();
1857 for(
unsigned int i=0 ; i < cy->
nbFeaturel1 ; i++){
1860 if (
m_w[n+i] < 0.5){
1882 for(
unsigned int i=cy->
nbFeaturel1 ; i < cy->nbFeature ; i++){
1885 if (
m_w[n+i] < 0.5){
1912 if((*it)->isTracked()){
1915 std::list<vpMeSite>::iterator itListCir;
1918 itListCir = ci->
meEllipse->getMeList().begin();
1922 for(
unsigned int i=0 ; i < ci->
nbFeature ; i++){
1925 if (
m_w[n+i] < 0.5){
1964 if((*it)->isTracked()){
1973 if((*it)->isTracked()){
1982 if((*it)->isTracked()){
1992 for (
unsigned int i = 0; i <
scales.size(); i += 1){
1994 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
1995 for(
unsigned int a = 0 ; a < (*it)->meline.size() ; a++){
1996 if((*it)->meline[a] != NULL){
1997 delete (*it)->meline[a];
1998 (*it)->meline[a] = NULL;
2000 (*it)->meline.clear();
2001 (*it)->nbFeature.clear();
2002 (*it)->nbFeatureTotal = 0;
2006 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
2007 if((*it)->meline1 != NULL){
2008 delete (*it)->meline1;
2009 (*it)->meline1 = NULL;
2011 if((*it)->meline2 != NULL){
2012 delete (*it)->meline2;
2013 (*it)->meline2 = NULL;
2016 (*it)->nbFeature = 0;
2017 (*it)->nbFeaturel1 = 0;
2018 (*it)->nbFeaturel2 = 0;
2021 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
2022 if((*it)->meEllipse != NULL){
2023 delete (*it)->meEllipse;
2024 (*it)->meEllipse = NULL;
2026 (*it)->nbFeature = 0;
2047 if (dx <= std::numeric_limits<double>::epsilon() && dy <= std::numeric_limits<double>::epsilon() && dz <= std::numeric_limits<double>::epsilon())
2068 bool already_here = false ;
2071 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2074 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2078 already_here = true ;
2107 lines[i].push_back(l);
2124 for(
unsigned int i=0; i<
scales.size(); i++){
2126 for(std::list<vpMbtDistanceLine*>::iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2128 if (name.compare(l->
getName()) == 0){
2150 bool already_here = false ;
2153 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2156 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
2204 bool already_here = false ;
2207 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2210 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
2246 for(
unsigned int i=0; i<
scales.size(); i++){
2248 for(std::list<vpMbtDistanceCylinder*>::iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
2250 if (name.compare(cy->
getName()) == 0){
2269 for(
unsigned int i=0; i<
scales.size(); i++){
2271 for(std::list<vpMbtDistanceCircle*>::iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
2273 if (name.compare(ci->
getName()) == 0){
2292 for (
unsigned int i=0 ; i < nbpt-1 ; i++)
2313 bool changed =
false;
2320 #ifdef VISP_HAVE_OGRE
2330 newvisibleline = true ;
2333 newvisibleline = false ;
2355 for (
unsigned int i=0 ; i < nbpt-1 ; i++)
2377 for (
unsigned int i=0 ; i < nbpt-1 ; i++)
2384 unsigned int &nberrors_cylinders,
unsigned int &nberrors_circles) {
2385 unsigned int nbrow = 0;
2387 nberrors_cylinders = 0;
2388 nberrors_circles = 0;
2440 const int idFace,
const std::string &name)
2442 addCircle(p1, p2, p3, radius, (
int)idFace, name);
2457 const std::string &name)
2475 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2477 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2479 if (l!=NULL)
delete l ;
2483 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
2485 if (cy!=NULL)
delete cy;
2489 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
2491 if (ci!=NULL)
delete ci;
2504 #ifdef VISP_HAVE_OGRE
2559 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2561 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2563 if (l!=NULL)
delete l ;
2567 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
2569 if (cy!=NULL)
delete cy;
2573 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
2575 if (ci!=NULL)
delete ci;
2615 unsigned int nbGoodPoints = 0;
2617 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[level].begin(); it!=
lines[level].end(); ++it){
2621 for(
unsigned int a = 0 ; a < l->
meline.size() ; a++){
2623 for(std::list<vpMeSite>::const_iterator itme=l->
meline[a]->getMeList().begin(); itme!=l->
meline[a]->getMeList().end(); ++itme){
2631 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[level].begin(); it!=
cylinders[level].end(); ++it){
2635 for(std::list<vpMeSite>::const_iterator itme1=cy->
meline1->getMeList().begin(); itme1!=cy->
meline1->getMeList().end(); ++itme1){
2638 for(std::list<vpMeSite>::const_iterator itme2=cy->
meline2->getMeList().begin(); itme2!=cy->
meline2->getMeList().end(); ++itme2){
2645 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[level].begin(); it!=
circles[level].end(); ++it){
2649 for(std::list<vpMeSite>::const_iterator itme=ci->
meEllipse->getMeList().begin(); itme!=ci->
meEllipse->getMeList().end(); ++itme){
2655 return nbGoodPoints;
2681 unsigned int nbActivatedLevels = 0;
2682 for (
unsigned int i = 0; i < scale.size(); i += 1){
2684 nbActivatedLevels++;
2687 if((scale.size() < 1) || (nbActivatedLevels == 0)){
2688 vpERROR_TRACE(
" !! WARNING : must use at least one level for the tracking. Use the global one");
2690 this->
scales.push_back(
true);
2698 lines.resize(scale.size());
2700 for (
unsigned int i = 0; i <
lines.size(); i += 1){
2716 vpTRACE(
"Far clipping value cannot be inferior than near clipping value. Far clipping won't be considered.");
2717 else if ( dist < 0 )
2718 vpTRACE(
"Far clipping value cannot be inferior than 0. Far clipping won't be considered.");
2723 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2725 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2743 vpTRACE(
"Near clipping value cannot be superior than far clipping value. Near clipping won't be considered.");
2744 else if ( dist < 0 )
2745 vpTRACE(
"Near clipping value cannot be inferior than 0. Near clipping won't be considered.");
2750 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2752 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2775 for (
unsigned int i = 0; i <
scales.size(); i += 1){
2777 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
2802 _pyramid.resize(
scales.size());
2811 for(
unsigned int i=1; i<_pyramid.size(); i += 1){
2813 unsigned int cScale =
static_cast<unsigned int>(pow(2., (
int)i));
2815 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION < 0x020408))
2816 IplImage* vpI0 = cvCreateImageHeader(cvSize((
int)_I.
getWidth(), (int)_I.
getHeight()), IPL_DEPTH_8U, 1);
2817 vpI0->imageData = (
char*)(_I.
bitmap);
2818 IplImage* vpI = cvCreateImage(cvSize((
int)(_I.
getWidth() / cScale), (
int)(_I.
getHeight() / cScale)), IPL_DEPTH_8U, 1);
2819 cvResize(vpI0, vpI, CV_INTER_NN);
2821 cvReleaseImage(&vpI);
2822 vpI0->imageData = NULL;
2823 cvReleaseImageHeader(&vpI0);
2825 for (
unsigned int k = 0, ii = 0; k < I->
getHeight(); k += 1, ii += cScale){
2826 for (
unsigned int l = 0, jj = 0; l < I->
getWidth(); l += 1, jj += cScale){
2827 (*I)[k][l] = _I[ii][jj];
2848 if(_pyramid.size() > 0){
2850 for (
unsigned int i = 1; i < _pyramid.size(); i += 1){
2851 if(_pyramid[i] != NULL){
2874 std::ostringstream oss;
2876 std::string errorMsg =
"level " + oss.str() +
" is not used, cannot get its distance lines.";
2880 linesList =
lines[level];
2898 std::ostringstream oss;
2900 std::string errorMsg =
"level " + oss.str() +
" is not used, cannot get its distance lines.";
2922 std::ostringstream oss;
2924 std::string errorMsg =
"level " + oss.str() +
" is not used, cannot get its distance lines.";
2940 const double ratio = pow(2., (
int)_scale);
2962 const double ratio = pow(2., (
int)_scale);
2991 if((*it)->isTracked()){
2999 if((*it)->isTracked()){
3007 if((*it)->isTracked()){
3027 for (
unsigned int i = 0; i <
scales.size(); i += 1){
3029 for(std::list<vpMbtDistanceLine*>::const_iterator it=
lines[i].begin(); it!=
lines[i].end(); ++it){
3038 (*it)->setTracked(name,useEdgeTracking);
3041 for(std::list<vpMbtDistanceCylinder*>::const_iterator it=
cylinders[i].begin(); it!=
cylinders[i].end(); ++it){
3042 if(
faces[(
unsigned)(*it)->index_polygon]->getName() == name){
3043 (*it)->setTracked(useEdgeTracking);
3047 for(std::list<vpMbtDistanceCircle*>::const_iterator it=
circles[i].begin(); it!=
circles[i].end(); ++it){
3048 if(
faces[(
unsigned)(*it)->index_polygon]->getName() == name){
3049 (*it)->setTracked(useEdgeTracking);
void setWindowName(const Ogre::String &n)
bool computeProjError
Flag used to specify if the gradient error criteria has to be computed or not.
void getLline(std::list< vpMbtDistanceLine * > &linesList, const unsigned int level=0) const
unsigned int ncylinder
Index of the cylinder to add, and total number of cylinders extracted so far.
void setMovingEdge(vpMe *Me)
void computeVVSFirstPhasePoseEstimation(const unsigned int nerror, const unsigned int iter, const vpColVector &factor, vpColVector &weighted_error, vpMatrix &L, bool &isoJoIdentity_)
Implementation of a matrix and operations on matrices.
void displayMovingEdges(const vpImage< unsigned char > &I)
vpMatrix covarianceMatrix
Covariance matrix.
void initFromCalibrationMatrix(const vpMatrix &_K)
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void setMovingEdge(const vpMe &me)
static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls, const vpMatrix &W)
unsigned int nbFeature
The number of moving edges.
unsigned int nbFeatureTotal
The number of moving edges.
void setVisible(bool _isvisible)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
void trackMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void setCameraParameters(const vpCameraParameters &camera)
void upScale(const unsigned int _scale)
std::string getName() const
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Compute the weights according a residue vector and a PsiFunction.
vpPoint * p3
An other point on the plane containing the circle.
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
void addLine(vpPoint &p1, vpPoint &p2, int polygon=-1, std::string name="")
bool isAppearing(const unsigned int i)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void getCameraParameters(vpCameraParameters &_cam) const
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
bool Reinit
Indicates if the line has to be reinitialized.
void setMeanWeight2(const double wmean)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void init(const vpImage< unsigned char > &I)
void track(const vpImage< unsigned char > &I)
double lambda
The gain of the virtual visual servoing stage.
unsigned int scaleLevel
Current scale level used. This attribute must not be modified outside of the downScale() and upScale(...
std::list< int > Lindex_polygon
Index of the faces which contain the line.
Type * bitmap
points toward the bitmap
vpMatrix L
The interaction matrix.
void setFarClippingDistance(const double &dist)
void setCameraParameters(const vpCameraParameters &camera)
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
std::vector< std::list< vpMbtDistanceCircle * > > circles
Vector of the tracked circles.
void getLcircle(std::list< vpMbtDistanceCircle * > &circlesList, const unsigned int level=0) const
Class to define colors available for display functionnalities.
Parse an Xml file to extract configuration parameters of a mbtConfig object.Data parser for the model...
void trackMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
vpHomogeneousMatrix cMo
The current pose.
vpPoint * p1
The first extremity.
void displayMovingEdges(const vpImage< unsigned char > &I)
double getNearClippingDistance() const
void setOgreShowConfigDialog(const bool showConfigDialog)
virtual ~vpMbEdgeTracker()
unsigned int ncircle
Index of the circle to add, and total number of circles extracted so far.
vpColVector error
The error vector.
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
double get_oY() const
Get the point Y coordinate in the object frame.
void getMe(vpMe &_ecm) const
void buildFrom(const vpPoint &_p1, const vpPoint &_p2, const vpPoint &_p3, const double r)
error that can be emited by ViSP classes.
vpMbtMeEllipse * meEllipse
The moving edge containers.
Manage a cylinder used in the model-based tracker.
void reInitLevel(const unsigned int _lvl)
vpPoint * p
corners in the object frame
Manage the line of a polygon used in the model-based tracker.
void computeVVSSecondPhaseWeights(const unsigned int iter, const unsigned int nerror, const unsigned int nbrow, vpColVector &weighted_error, vpRobust &robust_lines, vpRobust &robust_cylinders, vpRobust &robust_circles, vpColVector &w_lines, vpColVector &w_cylinders, vpColVector &w_circles, vpColVector &error_lines, vpColVector &error_cylinders, vpColVector &error_circles, const unsigned int nberrors_lines, const unsigned int nberrors_cylinders, const unsigned int nberrors_circles)
unsigned int nbFeature
The number of moving edges.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
bool samePoint(const vpPoint &P1, const vpPoint &P2) const
std::vector< const vpImage< unsigned char > * > Ipyramid
Pyramid of image associated to the current image. This pyramid is computed in the init() and in the t...
void removeCircle(const std::string &name)
bool useOgre
Use Ogre3d for visibility tests.
unsigned int getCols() const
Return the number of columns of the 2D array.
int index_polygon
Index of the faces which contain the line.
vpPoint * p2
A point on the plane containing the circle.
void setIndex(const unsigned int i)
virtual void setCameraParameters(const vpCameraParameters &camera)
void displayFeaturesOnImage(const vpImage< unsigned char > &I, const unsigned int lvl)
void computeVVS(const vpImage< unsigned char > &_I, const unsigned int lvl)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
unsigned int setVisibleOgre(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
void removeCylinder(const std::string &name)
vpMbtPolygon & getPolygon()
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
void loadConfigFile(const std::string &configFile)
vpMe me
The moving edges parameters.
void updateMovingEdge(const vpImage< unsigned char > &I)
std::vector< std::list< vpMbtDistanceLine * > > lines
Vector of list of all the lines tracked (each line is linked to a list of moving edges). Each element of the vector is for a scale (element 0 = level 0 = no subsampling).
virtual unsigned int getNbPoints(const unsigned int level=0) const
vpPoint * p1
The first extremity on the axe.
void initInteractionMatrixError()
void downScale(const unsigned int _scale)
void computeVVSSecondPhasePoseEstimation(const unsigned int nerror, vpMatrix &L, vpMatrix &L_true, vpMatrix &LVJ_true, vpColVector &W_true, const vpColVector &factor, const unsigned int iter, const bool isoJoIdentity_, vpColVector &weighted_error, double &mu, vpColVector &m_error_prev, vpColVector &m_w_prev, vpHomogeneousMatrix &cMoPrev, double &residu_1, double &r)
bool hasNearClippingDistance() const
Class that defines what is a point.
vpMatrix L
The interaction matrix.
vpMeSiteState getState() const
vpCameraParameters cam
The camera parameters.
void computeClippedPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
unsigned int setVisible(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
static Type maximum(const Type &a, const Type &b)
virtual void setNearClippingDistance(const double &dist)
double getFarClippingDistance() const
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
unsigned int nbFeaturel1
The number of moving edges on line 1.
double distFarClip
Distance for near clipping.
void computeJTR(const vpMatrix &J, const vpColVector &R, vpColVector &JTR) const
double projectionError
Error angle between the gradient direction of the model features projected at the resulting pose and ...
bool hasFarClippingDistance() const
vpAROgre * getOgreContext()
std::vector< vpMbtMeLine * > meline
The moving edge container.
int index_polygon
Index of the face which contains the cylinder.
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
void getLcylinder(std::list< vpMbtDistanceCylinder * > &cylindersList, const unsigned int level=0) const
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
Manage a circle used in the model-based tracker.
vpMatrix oJo
The Degrees of Freedom to estimate.
std::vector< bool > scales
Vector of scale level to use for the multi-scale tracking.
bool Reinit
Indicates if the circle has to be reinitialized.
Error that can be emited by the vpTracker class and its derivates.
double getAngleDisappear() const
Implementation of a polygon of the model used by the model-based tracker.
void initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
void setName(const std::string &circle_name)
std::string getName() const
vpPoint * p2
The second extremity.
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void diag(const double &val=1.0)
bool useScanLine
Use Scanline for visibility tests.
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double sqr(double x)
double minLineLengthThresholdGeneral
Minimum line length threshold for LOD mode (general setting)
void computeVVSSecondPhaseCheckLevenbergMarquardt(const unsigned int iter, const unsigned int nbrow, const vpColVector &m_error_prev, const vpColVector &m_w_prev, const vpHomogeneousMatrix &cMoPrev, double &mu, bool &reStartFromLastIncrement)
void setAngleDisappear(const double &adisappear)
double getMinPolygonAreaThreshold() const
vpColVector error
The error vector.
void trackMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
vpColVector m_error
Error s-s*.
unsigned int nbFeaturesForProjErrorComputation
Number of features used in the computation of the projection error.
Generic class defining intrinsic camera parameters.
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
double get_oZ() const
Get the point Z coordinate in the object frame.
unsigned int initMbtTracking(unsigned int &nberrors_lines, unsigned int &nberrors_cylinders, unsigned int &nberrors_circles)
void setIndex(const unsigned int i)
double percentageGdPt
Percentage of good points over total number of points below which tracking is supposed to have failed...
void initPyramid(const vpImage< unsigned char > &_I, std::vector< const vpImage< unsigned char > * > &_pyramid)
void cleanPyramid(std::vector< const vpImage< unsigned char > * > &_pyramid)
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
vpMbtMeLine * meline1
The moving edge containers (first line of the cylinder)
void setVisible(bool _isvisible)
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
virtual void setFarClippingDistance(const double &dist)
static Type minimum(const Type &a, const Type &b)
Implementation of a velocity twist matrix and operations on such kind of matrices.
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
unsigned int getRows() const
Return the number of rows of the 2D array.
void setCameraParameters(const vpCameraParameters &_cam)
void computeVVSFirstPhase(const vpImage< unsigned char > &I, const unsigned int iter, vpMatrix &L, vpColVector &factor, double &count, vpColVector &error, vpColVector &w_mbt, const unsigned int lvl=0)
double angleAppears
Angle used to detect a face appearance.
void setState(const vpMeSiteState &flag)
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &_cMo)
void displayMovingEdges(const vpImage< unsigned char > &I)
std::string getName() const
static double rad(double deg)
void addCylinder(const vpPoint &P1, const vpPoint &P2, const double r, int idFace=-1, const std::string &name="")
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
void parse(const char *filename)
void setMeanWeight1(const double wmean)
void setClipping(const unsigned int &flags)
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void setMovingEdge(vpMe *Me)
void computeProjectionError(const vpImage< unsigned char > &_I)
void setVisible(bool _isvisible)
virtual void initFaceFromLines(vpMbtPolygon &polygon)
double getMinLineLengthThreshold() const
void setScales(const std::vector< bool > &_scales)
vpPoint * p2
The second extremity on the axe.
void setCameraParameters(const vpCameraParameters &camera)
double get_oX() const
Get the point X coordinate in the object frame.
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
void setIndex(const unsigned int i)
double minPolygonAreaThresholdGeneral
Minimum polygon area threshold for LOD mode (general setting)
static double deg(double rad)
void initInteractionMatrixError()
bool displayFeatures
If true, the features are displayed.
virtual void loadModel(const char *modelFile, const bool verbose=false)
void buildFrom(const vpPoint &_p1, const vpPoint &_p2, const double r)
bool ogreShowConfigDialog
bool applyLodSettingInConfig
True if the CAO model is loaded before the call to loadConfigFile, (deduced by the number of polygons...
Implementation of column vector and the associated operations.
std::vector< std::list< vpMbtDistanceCylinder * > > cylinders
Vector of the tracked cylinders.
void setAngleAppear(const double &aappear)
void setMovingEdge(vpMe *Me)
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")
vpHomogeneousMatrix inverse() const
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
static vpHomogeneousMatrix direct(const vpColVector &v)
void setMeanWeight(const double _wmean)
bool isVisible(const unsigned int i)
Contains an M-Estimator and various influence function.
void updateMovingEdgeWeights()
unsigned int nbvisiblepolygone
Number of polygon (face) currently visible.
double angleDisappears
Angle used to detect a face disappearance.
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
virtual unsigned int getNbPolygon() const
void visibleFace(const vpImage< unsigned char > &_I, const vpHomogeneousMatrix &_cMo, bool &newvisibleline)
void addPolygon(const int &index)
void setNearClippingDistance(const double &dist)
unsigned int getHeight() const
unsigned int getNbPoint() const
void setMeanWeight(const double w_mean)
vpColVector error
The error vector.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
virtual void setClipping(const unsigned int &flags)
bool Reinit
Indicates if the line has to be reinitialized.
double radius
The radius of the cylinder.
unsigned int clippingFlag
Flags specifying which clipping to used.
unsigned int nline
Index of the polygon to add, and total number of polygon extracted so far.
void addPolygon(vpMbtPolygon &p)
void setName(const std::string line_name)
void trackMovingEdge(const vpImage< unsigned char > &I)
void displayOgre(const vpHomogeneousMatrix &cMo)
double getAngleAppear() const
virtual void setClipping(const unsigned int &flags)
unsigned int nbFeaturel2
The number of moving edges on line 2.
void computeVVSFirstPhaseFactor(const vpImage< unsigned char > &I, vpColVector &factor, const unsigned int lvl=0)
void setUseEdgeTracking(const std::string &name, const bool &useEdgeTracking)
void setThreshold(const double noise_threshold)
double radius
The radius of the circle.
virtual void setFarClippingDistance(const double &dist)
void setName(const std::string &cyl_name)
static int() sign(double x)
vpMbtMeLine * meline2
The moving edge containers (second line of the cylinder)
void removeLine(const std::string &name)
bool getFovClipping() const
void setIteration(const unsigned int iter)
Set iteration.
double distNearClip
Distance for near clipping.
bool useLodGeneral
True if LOD mode is enabled.
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
vpMatrix L
The interaction matrix.
void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, int idFace=-1, const std::string &name="")
std::vector< unsigned int > nbFeature
The number of moving edges.
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo, const vpImage< unsigned char > &I)
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void initInteractionMatrixError()
void setMovingEdge(const vpMe &_ecm)
bool isoJoIdentity
Boolean to know if oJo is identity (for fast computation)
std::string getName() const
vpPoint * p1
The center of the circle.
void computeVVSSecondPhase(const vpImage< unsigned char > &I, vpMatrix &L, vpColVector &error_lines, vpColVector &error_cylinders, vpColVector &error_circles, vpColVector &error, const unsigned int lvl)
bool useScanLine
Use scanline rendering.
void buildFrom(vpPoint &_p1, vpPoint &_p2)
void resize(const unsigned int i, const bool flagNullify=true)
vpColVector m_w
Weights used in the robust scheme.
virtual void setLod(const bool useLod, const std::string &name="")
virtual void setNearClippingDistance(const double &dist)
void computeFov(const unsigned int &w, const unsigned int &h)