45 #include <visp3/core/vpConfig.h>
47 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
49 #include <visp3/core/vpTrackingException.h>
50 #include <visp3/core/vpVelocityTwistMatrix.h>
51 #include <visp3/mbt/vpMbKltMultiTracker.h>
58 m_referenceCameraName(
"Camera") {
71 m_mapOfKltTrackers(), m_referenceCameraName(
"Camera") {
75 }
else if(nbCameras == 1) {
80 }
else if(nbCameras == 2) {
91 for(
unsigned int i = 1; i <= nbCameras; i++) {
111 m_mapOfKltTrackers(), m_referenceCameraName(
"Camera") {
112 if(cameraNames.empty()) {
116 for(std::vector<std::string>::const_iterator it = cameraNames.begin(); it != cameraNames.end(); ++it) {
128 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
146 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
148 it->second->addCircle(P1, P2, P3, r, name);
161 unsigned int nbInfos = 0;
162 for(std::map<std::string, unsigned int>::const_iterator it = mapOfNbInfos.begin(); it != mapOfNbInfos.end(); ++it) {
163 nbInfos += it->second;
166 std::map<std::string, vpRobust> mapOfRobusts;
168 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
170 mapOfRobusts[it->first] =
vpRobust(2*mapOfNbInfos[it->first]);
181 double normRes_1 = -1;
182 unsigned int iter = 0;
184 std::map<std::string, vpVelocityTwistMatrix> mapOfVelocityTwist;
189 mapOfVelocityTwist[it->first] = cVo;
192 while( ((
int)((normRes - normRes_1)*1e8) != 0 ) && (iter<
maxIter) ) {
196 for(std::map<std::string, vpMbKltTracker*>::const_iterator it1 =
m_mapOfKltTrackers.begin();
198 unsigned int shift = 0;
203 R_current.
resize(2 * mapOfNbInfos[it1->first]);
204 L_current.
resize(2 * mapOfNbInfos[it1->first], 6, 0);
211 it1->second->kltPolygons, it1->second->kltCylinders,
ctTc0);
216 it1->second->kltPolygons, it1->second->kltCylinders, c_curr_tTc_curr0);
220 L_current = L_current*mapOfVelocityTwist[it1->first];
227 bool reStartFromLastIncrement =
false;
230 if(!reStartFromLastIncrement) {
233 computeVVSPoseEstimation(iter, L, w, L_true, LVJ_true, normRes, normRes_1, w_true, R, LTL, LTR,
234 error_prev, v, mu, cMoPrev, ctTc0_Prev);
245 std::map<std::string, vpRobust> &mapOfRobusts,
double threshold) {
253 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
256 it->second->getCameraParameters(camTmp);
257 mapOfRobusts[it->first].setThreshold(threshold / camTmp.
get_px());
261 unsigned int shift = 0;
262 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
264 if(mapOfNbInfos[it->first] > 0) {
267 shift += 2*mapOfNbInfos[it->first];
269 mapOfRobusts[it->first].setIteration(iter);
289 it->second->display(I, cMo_, cam_, col, thickness, displayFullModel);
306 const vpColor& color ,
const unsigned int thickness,
const bool displayFullModel) {
309 it->second->display(I, cMo_, cam_, color, thickness, displayFullModel);
332 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
333 it->second->display(I1, c1Mo, cam1, color, thickness, displayFullModel);
336 it->second->display(I2, c2Mo, cam2, color, thickness, displayFullModel);
338 std::cerr <<
"This display is only for the stereo case ! There are "
360 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
361 it->second->display(I1, c1Mo, cam1, color, thickness, displayFullModel);
364 it->second->display(I2, c2Mo, cam2, color, thickness, displayFullModel);
366 std::cerr <<
"This display is only for the stereo case ! There are "
382 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
383 const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
384 const vpColor& col,
const unsigned int thickness,
const bool displayFullModel) {
388 it_img != mapOfImages.end(); ++it_img) {
389 std::map<std::string, vpMbKltTracker *>::const_iterator it_klt =
m_mapOfKltTrackers.find(it_img->first);
390 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(it_img->first);
391 std::map<std::string, vpCameraParameters>::const_iterator it_cam = mapOfCameraParameters.find(it_img->first);
393 if(it_klt !=
m_mapOfKltTrackers.end() && it_camPose != mapOfCameraPoses.end() && it_cam != mapOfCameraParameters.end()) {
394 it_klt->second->display(*it_img->second, it_camPose->second, it_cam->second, col, thickness, displayFullModel);
396 std::cerr <<
"Missing elements ! " << std::endl;
412 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
413 const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
414 const vpColor& col,
const unsigned int thickness,
const bool displayFullModel) {
417 for(std::map<std::string,
const vpImage<vpRGBa> *>::const_iterator it_img = mapOfImages.begin();
418 it_img != mapOfImages.end(); ++it_img) {
419 std::map<std::string, vpMbKltTracker *>::const_iterator it_klt =
m_mapOfKltTrackers.find(it_img->first);
420 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(it_img->first);
421 std::map<std::string, vpCameraParameters>::const_iterator it_cam = mapOfCameraParameters.find(it_img->first);
423 if(it_klt !=
m_mapOfKltTrackers.end() && it_camPose != mapOfCameraPoses.end() && it_cam != mapOfCameraParameters.end()) {
424 it_klt->second->display(*it_img->second, it_camPose->second, it_cam->second, col, thickness, displayFullModel);
426 std::cerr <<
"Missing elements ! " << std::endl;
437 std::vector<std::string> cameraNames;
439 for(std::map<std::string, vpMbKltTracker *>::const_iterator it_klt =
m_mapOfKltTrackers.begin();
441 cameraNames.push_back(it_klt->first);
456 it->second->getCameraParameters(camera);
458 std::cerr <<
"The reference camera name: " <<
m_referenceCameraName <<
" does not exist !" << std::endl;
470 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
471 it->second->getCameraParameters(cam1);
474 it->second->getCameraParameters(cam2);
476 std::cerr <<
"Problem with the number of cameras ! There are "
488 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
490 it->second->getCameraParameters(camera);
492 std::cerr <<
"The camera: " << cameraName <<
" does not exist !" << std::endl;
503 mapOfCameraParameters.clear();
505 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
508 it->second->getCameraParameters(cam_);
509 mapOfCameraParameters[it->first] = cam_;
520 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
522 return it->second->getClipping();
524 std::cerr <<
"Cannot find camera: " << cameraName << std::endl;
538 return it->second->getFaces();
551 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
553 return it->second->getFaces();
556 std::cerr <<
"The camera: " << cameraName <<
" cannot be found !" << std::endl;
566 std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > mapOfFaces;
567 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
569 mapOfFaces[it->first] = it->second->faces;
584 return it_klt->second->getFeaturesCircle();
599 std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
602 return it->second->getFeaturesCircle();
604 std::cerr <<
"The camera: " << cameraName <<
" does not exist !";
620 return it_klt->second->getFeaturesKlt();
636 std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
639 return it->second->getFeaturesKlt();
641 std::cerr <<
"The camera: " << cameraName <<
" does not exist !";
656 return it_klt->second->getFeaturesKltCylinder();
671 std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
674 return it->second->getFeaturesKltCylinder();
676 std::cerr <<
"The camera: " << cameraName <<
" does not exist !";
691 std::map<std::string, std::vector<vpImagePoint> > mapOfFeatures;
693 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
695 mapOfFeatures[it->first] = it->second->getKltImagePoints();
698 return mapOfFeatures;
710 std::map<std::string, std::map<int, vpImagePoint> > mapOfFeatures;
712 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
714 mapOfFeatures[it->first] = it->second->getKltImagePointsWithId();
717 return mapOfFeatures;
726 std::map<std::string, vpKltOpencv> mapOfKltOpenCVTracker;
728 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
730 mapOfKltOpenCVTracker[it->first] = it->second->getKltOpencv();
733 return mapOfKltOpenCVTracker;
741 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
743 std::map<std::string, std::vector<cv::Point2f> > mapOfFeatures;
745 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
747 mapOfFeatures[it->first] = it->second->getKltPoints();
750 return mapOfFeatures;
754 std::map<std::string, CvPoint2D32f*> mapOfFeatures;
756 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
758 mapOfFeatures[it->first] = it->second->getKltPoints();
761 return mapOfFeatures;
771 std::map<std::string, int> mapOfFeatures;
773 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
775 mapOfFeatures[it->first] = it->second->getNbKltPoints();
778 return mapOfFeatures;
789 return it->second->getNbPolygon();
802 std::map<std::string, unsigned int> mapOfNbPolygons;
803 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
805 mapOfNbPolygons[it->first] = it->second->getNbPolygon();
808 return mapOfNbPolygons;
819 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
820 it->second->getPose(c1Mo);
823 it->second->getPose(c2Mo);
825 std::cerr <<
"Require two cameras ! There are "
839 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
841 it->second->getPose(cMo_);
843 std::cerr <<
"The camera: " << cameraName <<
" does not exist !" << std::endl;
854 mapOfCameraPoses.clear();
856 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
859 it->second->getPose(cMo_);
860 mapOfCameraPoses[it->first] = cMo_;
867 #ifdef VISP_HAVE_MODULE_GUI
878 const std::string &displayFile) {
887 it->second->initClick(I, points3D_list, displayFile);
888 it->second->getPose(
cMo);
894 std::stringstream ss;
930 it->second->initClick(I, initFile, displayHelp);
931 it->second->getPose(
cMo);
937 std::stringstream ss;
968 const std::string& initFile1,
const std::string& initFile2,
const bool displayHelp,
const bool firstCameraIsReference) {
970 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
971 it->second->initClick(I1, initFile1, displayHelp);
973 if(firstCameraIsReference) {
975 it->second->getPose(
cMo);
978 it->second->getCameraParameters(this->
cam);
987 it->second->initClick(I2, initFile2, displayHelp);
989 if(!firstCameraIsReference) {
991 it->second->getPose(
cMo);
994 it->second->getCameraParameters(this->
cam);
1001 std::stringstream ss;
1002 ss <<
"Cannot init click ! Require two cameras but there are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
1029 const std::string &initFile,
const bool displayHelp) {
1032 std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(
m_referenceCameraName);
1034 if(it_img != mapOfImages.end()) {
1035 it_klt->second->initClick(*it_img->second, initFile, displayHelp);
1038 it_klt->second->getPose(
cMo);
1047 it_img = mapOfImages.find(it_klt->first);
1048 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans =
1053 it_klt->second->cMo = cCurrentMo;
1054 it_klt->second->
init(*it_img->second);
1056 std::stringstream ss;
1063 std::stringstream ss;
1068 std::stringstream ss;
1097 const std::map<std::string, std::string> &mapOfInitFiles,
const bool displayHelp) {
1099 std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(
m_referenceCameraName);
1100 std::map<std::string, std::string>::const_iterator it_initFile = mapOfInitFiles.find(
m_referenceCameraName);
1102 if(it_klt !=
m_mapOfKltTrackers.end() && it_img != mapOfImages.end() && it_initFile != mapOfInitFiles.end()) {
1103 it_klt->second->initClick(*it_img->second, it_initFile->second, displayHelp);
1104 it_klt->second->getPose(
cMo);
1113 std::vector<std::string> vectorOfMissingCameraPoses;
1118 it_img = mapOfImages.find(it_klt->first);
1119 it_initFile = mapOfInitFiles.find(it_klt->first);
1121 if(it_img != mapOfImages.end() && it_initFile != mapOfInitFiles.end()) {
1123 it_klt->second->initClick(*it_img->second, it_initFile->second, displayHelp);
1125 vectorOfMissingCameraPoses.push_back(it_klt->first);
1131 for(std::vector<std::string>::const_iterator it1 = vectorOfMissingCameraPoses.begin();
1132 it1 != vectorOfMissingCameraPoses.end(); ++it1) {
1133 it_img = mapOfImages.find(*it1);
1141 std::stringstream ss;
1142 ss <<
"Missing image or missing camera transformation matrix ! Cannot set the pose for camera: " << (*it1) <<
" !";
1147 #endif //#ifdef VISP_HAVE_MODULE_GUI
1173 char s[FILENAME_MAX];
1174 std::fstream finit ;
1177 std::string ext =
".pos";
1178 size_t pos = initFile.rfind(ext);
1180 if( pos == initFile.size()-ext.size() && pos != 0)
1181 sprintf(s,
"%s", initFile.c_str());
1183 sprintf(s,
"%s.pos", initFile.c_str());
1185 finit.open(s,std::ios::in) ;
1187 std::cerr <<
"cannot read " << s << std::endl;
1191 for (
unsigned int i = 0; i < 6; i += 1){
1192 finit >> init_pos[i];
1206 it_ref->second->initFromPose(I,
cMo);
1226 it_ref->second->initFromPose(I,
cMo);
1252 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1253 it->second->initFromPose(I1, c1Mo);
1257 it->second->initFromPose(I2, c2Mo);
1259 if(firstCameraIsReference) {
1268 std::stringstream ss;
1269 ss <<
"This method requires 2 cameras but there are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
1285 std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(it_klt->first);
1287 if(it_img != mapOfImages.end()) {
1288 it_klt->second->initFromPose(*it_img->second, cMo_);
1296 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans =
1298 it_img = mapOfImages.find(it_klt->first);
1302 it_klt->second->initFromPose(*it_img->second, cCurrentMo);
1312 std::stringstream ss;
1325 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) {
1328 std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(
m_referenceCameraName);
1329 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(
m_referenceCameraName);
1331 if(it_klt !=
m_mapOfKltTrackers.end() && it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
1332 it_klt->second->initFromPose(*it_img->second, it_camPose->second);
1333 it_klt->second->getPose(
cMo);
1342 std::vector<std::string> vectorOfMissingCameraPoses;
1346 it_img = mapOfImages.find(it_klt->first);
1347 it_camPose = mapOfCameraPoses.find(it_klt->first);
1349 if(it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
1351 it_klt->second->initFromPose(*it_img->second, it_camPose->second);
1353 vectorOfMissingCameraPoses.push_back(it_klt->first);
1357 for(std::vector<std::string>::const_iterator it1 = vectorOfMissingCameraPoses.begin();
1358 it1 != vectorOfMissingCameraPoses.end(); ++it1) {
1359 it_img = mapOfImages.find(*it1);
1366 std::stringstream ss;
1367 ss <<
"Missing image or missing camera transformation matrix ! Cannot set the pose for camera: " << (*it1) <<
" !";
1423 it->second->loadConfigFile(configFile);
1424 it->second->getCameraParameters(
cam);
1431 std::stringstream ss;
1452 const bool firstCameraIsReference) {
1454 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1455 it->second->loadConfigFile(configFile1);
1457 if(firstCameraIsReference) {
1458 it->second->getCameraParameters(
cam);
1467 it->second->loadConfigFile(configFile2);
1469 if(!firstCameraIsReference) {
1470 it->second->getCameraParameters(
cam);
1478 std::stringstream ss;
1479 ss <<
"Cannot loadConfigFile. Require two cameras ! There are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
1497 for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt =
m_mapOfKltTrackers.begin();
1499 std::map<std::string, std::string>::const_iterator it_config = mapOfConfigFiles.find(it_klt->first);
1500 if(it_config != mapOfConfigFiles.end()) {
1501 it_klt->second->loadConfigFile(it_config->second);
1503 std::stringstream ss;
1504 ss <<
"Missing configuration file for camera: " << it_klt->first <<
" !";
1512 it->second->getCameraParameters(
cam);
1519 std::stringstream ss;
1551 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1553 it->second->loadModel(modelFile, verbose);
1560 std::map<std::string, unsigned int> &mapOfNbInfos,
1561 std::map<std::string, unsigned int> &mapOfNbFaceUsed) {
1562 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
1564 mapOfNbInfos[it->first] = 0;
1565 mapOfNbFaceUsed[it->first] = 0;
1568 for (std::map<std::string, vpMbKltTracker*>::const_iterator it =
1571 it->second->preTracking(*mapOfImages[it->first], mapOfNbInfos[it->first], mapOfNbFaceUsed[it->first]);
1579 std::map<std::string, unsigned int> &mapOfNbInfos,
vpColVector &w_klt) {
1580 unsigned int shift = 0;
1581 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1586 if(mapOfNbInfos[it->first] > 0) {
1588 shift += 2*mapOfNbInfos[it->first];
1589 if(it->second->postTracking(*mapOfImages[it->first], sub_w)) {
1590 it->second->reinit(*mapOfImages[it->first]);
1621 std::stringstream ss;
1622 ss <<
"This method requires exactly one camera, there are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
1631 it_klt->second->reInitModel(I, cad_name, cMo_, verbose);
1634 it_klt->second->getPose(
cMo);
1657 const bool verbose,
const bool firstCameraIsReference) {
1659 std::map<std::string, vpMbKltTracker *>::const_iterator it_edge =
m_mapOfKltTrackers.begin();
1661 it_edge->second->reInitModel(I1, cad_name, c1Mo, verbose);
1663 if(firstCameraIsReference) {
1665 it_edge->second->getPose(
cMo);
1670 it_edge->second->reInitModel(I2, cad_name, c2Mo, verbose);
1672 if(!firstCameraIsReference) {
1674 it_edge->second->getPose(
cMo);
1694 const std::string &cad_name,
const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
1695 const bool verbose) {
1697 std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(
m_referenceCameraName);
1698 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(
m_referenceCameraName);
1700 if(it_klt !=
m_mapOfKltTrackers.end() && it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
1701 it_klt->second->reInitModel(*it_img->second, cad_name, it_camPose->second, verbose);
1705 it_klt->second->getPose(
cMo);
1713 std::vector<std::string> vectorOfMissingCameras;
1716 it_img = mapOfImages.find(it_klt->first);
1717 it_camPose = mapOfCameraPoses.find(it_klt->first);
1719 if(it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
1720 it_klt->second->reInitModel(*it_img->second, cad_name, it_camPose->second, verbose);
1722 vectorOfMissingCameras.push_back(it_klt->first);
1727 for(std::vector<std::string>::const_iterator it = vectorOfMissingCameras.begin();
1728 it != vectorOfMissingCameras.end(); ++it) {
1729 it_img = mapOfImages.find(*it);
1734 m_mapOfKltTrackers[*it]->reInitModel(*it_img->second, cad_name, cCurrentMo, verbose);
1748 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1750 it->second->resetTracker();
1773 #ifdef VISP_HAVE_OGRE
1790 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1792 it->second->setAngleAppear(a);
1808 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1810 it->second->setAngleDisappear(a);
1827 it->second->setCameraParameters(camera);
1832 std::stringstream ss;
1847 const bool firstCameraIsReference) {
1851 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1852 it->second->setCameraParameters(camera1);
1855 it->second->setCameraParameters(camera2);
1857 if(firstCameraIsReference) {
1858 this->
cam = camera1;
1860 this->
cam = camera2;
1863 std::stringstream ss;
1864 ss <<
"Require two cameras ! There are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
1876 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
1878 it->second->setCameraParameters(camera);
1884 std::stringstream ss;
1885 ss <<
"The camera: " << cameraName <<
" does not exist !";
1896 for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt =
m_mapOfKltTrackers.begin();
1898 std::map<std::string, vpCameraParameters>::const_iterator it_cam = mapOfCameraParameters.find(it_klt->first);
1899 if(it_cam != mapOfCameraParameters.end()) {
1900 it_klt->second->setCameraParameters(it_cam->second);
1903 this->
cam = it_cam->second;
1906 std::stringstream ss;
1907 ss <<
"Missing camera parameters for camera: " << it_klt->first <<
" !";
1923 it->second = cameraTransformationMatrix;
1925 std::stringstream ss;
1926 ss <<
"Cannot find camera: " << cameraName <<
" !";
1938 const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix) {
1940 for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt =
m_mapOfKltTrackers.begin();
1942 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans = mapOfTransformationMatrix.find(it_klt->first);
1944 if(it_camTrans == mapOfTransformationMatrix.end()) {
1962 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1964 it->second->setClipping(flags);
1977 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
1979 it->second->setClipping(flags);
1981 std::cerr <<
"Camera: " << cameraName <<
" does not exist !" << std::endl;
1993 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
1995 it->second->setCovarianceComputation(flag);
2005 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2007 it->second->setDisplayFeatures(displayF);
2021 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2023 it->second->setFarClippingDistance(dist);
2034 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
2036 it->second->setFarClippingDistance(dist);
2038 std::cerr <<
"Camera: " << cameraName <<
" does not exist !" << std::endl;
2042 #ifdef VISP_HAVE_OGRE
2051 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2053 it->second->setGoodNbRayCastingAttemptsRatio(ratio);
2066 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2068 it->second->setNbRayCastingAttemptsForVisibility(attempts);
2079 for(std::map<std::string, vpMbKltTracker *>::const_iterator it_klt =
m_mapOfKltTrackers.begin();
2081 it_klt->second->setKltOpencv(t);
2091 for(std::map<std::string, vpKltOpencv>::const_iterator it_kltOpenCV = mapOfOpenCVTrackers.begin();
2092 it_kltOpenCV != mapOfOpenCVTrackers.end(); ++it_kltOpenCV) {
2093 std::map<std::string, vpMbKltTracker*>::const_iterator it_klt =
m_mapOfKltTrackers.find(it_kltOpenCV->first);
2095 it_klt->second->setKltOpencv(it_kltOpenCV->second);
2097 std::cerr <<
"The camera: " << it_kltOpenCV->first <<
" does not exist !" << std::endl;
2112 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2114 it->second->setLod(useLod, name);
2129 std::map<std::string, vpMbKltTracker *>::const_iterator it_klt =
m_mapOfKltTrackers.find(cameraName);
2132 it_klt->second->setLod(useLod, name);
2134 std::cerr <<
"The camera: " << cameraName <<
" cannot be found !" << std::endl;
2144 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
2146 it->second->setMaskBorder(e);
2156 std::cerr <<
"Useless for KLT tracker !" << std::endl;
2168 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2170 it->second->setMinPolygonAreaThresh(minPolygonAreaThresh, name);
2184 const std::string &name) {
2185 std::map<std::string, vpMbKltTracker *>::const_iterator it_klt =
m_mapOfKltTrackers.find(cameraName);
2188 it_klt->second->setMinPolygonAreaThresh(minPolygonAreaThresh, name);
2190 std::cerr <<
"The camera: " << cameraName <<
" cannot be found !" << std::endl;
2202 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2204 it->second->setNearClippingDistance(dist);
2219 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2221 it->second->setOgreShowConfigDialog(showConfigDialog);
2233 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2235 it->second->setOgreVisibilityTest(v);
2238 #ifdef VISP_HAVE_OGRE
2239 for(std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2241 it->second->faces.getOgreContext()->setWindowName(
"Multi MBT Klt (" + it->first +
")");
2255 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.find(cameraName);
2257 it->second->setNearClippingDistance(dist);
2259 std::cerr <<
"Camera: " << cameraName <<
" does not exist !" << std::endl;
2269 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
2271 it->second->setOptimizationMethod(opt);
2288 it->second->setPose(I, cMo_);
2294 std::stringstream ss;
2299 std::stringstream ss;
2300 ss <<
"You are trying to set the pose with only one image and cMo "
2301 "but there are multiple cameras !";
2319 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2320 it->second->setPose(I1, c1Mo);
2324 it->second->setPose(I2, c2Mo);
2326 if(firstCameraIsReference) {
2335 std::stringstream ss;
2336 ss <<
"This method requires 2 cameras but there are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
2353 std::map<std::string, const vpImage<unsigned char> *>::const_iterator it_img = mapOfImages.find(
m_referenceCameraName);
2355 if(it_img != mapOfImages.end()) {
2357 it_klt->second->setPose(*it_img->second, cMo_);
2368 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camTrans =
2370 it_img = mapOfImages.find(it_klt->first);
2374 it_klt->second->setPose(*it_img->second, cCurrentMo);
2381 std::stringstream ss;
2386 std::stringstream ss;
2402 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) {
2405 std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(
m_referenceCameraName);
2406 std::map<std::string, vpHomogeneousMatrix>::const_iterator it_camPose = mapOfCameraPoses.find(
m_referenceCameraName);
2408 if(it_klt !=
m_mapOfKltTrackers.end() && it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
2409 it_klt->second->setPose(*it_img->second, it_camPose->second);
2410 it_klt->second->getPose(
cMo);
2419 std::vector<std::string> vectorOfMissingCameraPoses;
2424 it_img = mapOfImages.find(it_klt->first);
2425 it_camPose = mapOfCameraPoses.find(it_klt->first);
2427 if(it_img != mapOfImages.end() && it_camPose != mapOfCameraPoses.end()) {
2429 it_klt->second->setPose(*it_img->second, it_camPose->second);
2431 vectorOfMissingCameraPoses.push_back(it_klt->first);
2436 for(std::vector<std::string>::const_iterator it1 = vectorOfMissingCameraPoses.begin();
2437 it1 != vectorOfMissingCameraPoses.end(); ++it1) {
2438 it_img = mapOfImages.find(*it1);
2445 std::stringstream ss;
2446 ss <<
"Missing image or missing camera transformation matrix ! Cannot set the pose for camera: " << (*it1) <<
" !";
2458 std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.find(referenceCameraName);
2462 std::stringstream ss;
2463 ss <<
"The reference camera: " << referenceCameraName <<
" does not exist !";
2477 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
2479 it->second->setScanLineVisibilityTest(v);
2489 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
2491 it->second->setThresholdAcceptation(th);
2504 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
2506 it->second->setUseKltTracking(name, useKltTracking);
2523 it->second->track(I);
2524 it->second->getPose(
cMo);
2526 std::stringstream ss;
2542 std::map<std::string, vpMbKltTracker *>::const_iterator it =
m_mapOfKltTrackers.begin();
2543 std::map<std::string, const vpImage<unsigned char> *> mapOfImages;
2544 mapOfImages[it->first] = &I1;
2547 mapOfImages[it->first] = &I2;
2550 std::stringstream ss;
2551 ss <<
"Require two cameras ! There are " <<
m_mapOfKltTrackers.size() <<
" cameras !";
2565 for(std::map<std::string, vpMbKltTracker*>::const_iterator it_klt =
m_mapOfKltTrackers.begin();
2567 std::map<std::string, const vpImage<unsigned char>* >::const_iterator it_img = mapOfImages.find(it_klt->first);
2569 if(it_img == mapOfImages.end()) {
2574 std::map<std::string, unsigned int> mapOfNbInfos;
2575 std::map<std::string, unsigned int> mapOfNbFaceUsed;
2577 preTracking(mapOfImages, mapOfNbInfos, mapOfNbFaceUsed);
2579 bool atLeastOneTrackerOk =
false;
2580 for(std::map<std::string, vpMbKltTracker*>::const_iterator it =
m_mapOfKltTrackers.begin();
2582 if(mapOfNbInfos[it->first] >= 4 && mapOfNbFaceUsed[it->first] != 0) {
2583 atLeastOneTrackerOk =
true;
2587 if(!atLeastOneTrackerOk) {
2597 #elif !defined(VISP_BUILD_SHARED_LIBS)
2599 void dummy_vpMbKltMultiTracker() {};
2600 #endif //VISP_HAVE_OPENCV
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
std::list< vpMbtDistanceKltPoints * > kltPolygons
virtual unsigned int getNbPolygon() const
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
virtual void setCovarianceComputation(const bool &flag)
Implementation of a matrix and operations on matrices.
virtual std::vector< std::string > getCameraNames() const
virtual void getCameraParameters(vpCameraParameters &camera) const
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
virtual void setFarClippingDistance(const double &dist)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
void computeVVSPoseEstimation(const unsigned int iter, vpMatrix &L, const vpColVector &w, vpMatrix &L_true, vpMatrix &LVJ_true, double &normRes, double &normRes_1, vpColVector &w_true, vpColVector &R, vpMatrix <L, vpColVector <R, vpColVector &error_prev, vpColVector &v, double &mu, vpHomogeneousMatrix &cMoPrev, vpHomogeneousMatrix &ctTc0_Prev)
virtual void track(const vpImage< unsigned char > &I)
virtual void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="")
virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking)
virtual void setCovarianceComputation(const bool &flag)
virtual unsigned int getClipping() const
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
void stack(const double &d)
virtual void setAngleDisappear(const double &a)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
virtual std::map< std::string, int > getNbKltPoints() const
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
virtual void computeVVSWeights(const unsigned int iter, const unsigned int nbInfos, std::map< std::string, unsigned int > &mapOfNbInfos, vpColVector &R, vpColVector &w_true, vpColVector &w, std::map< std::string, vpRobust > &mapOfRobusts, double threshold)
virtual void setAngleDisappear(const double &a)
virtual void loadConfigFile(const std::string &configFile)
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void computeVVS(std::map< std::string, unsigned int > &mapOfNbInfos, vpColVector &w)
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual void preTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, unsigned int > &mapOfNbInfos, std::map< std::string, unsigned int > &mapOfNbFaceUsed)
Class to define colors available for display functionnalities.
double percentGood
Percentage of good points, according to the initial number, that must have the tracker.
vpHomogeneousMatrix cMo
The current pose.
void stack(const vpMatrix &A)
virtual void setDisplayFeatures(const bool displayF)
virtual void setCameraTransformationMatrix(const std::string &cameraName, const vpHomogeneousMatrix &cameraTransformationMatrix)
virtual 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)
bool modelInitialised
Flag used to ensure that the CAD model is loaded before the initialisation.
error that can be emited by ViSP classes.
virtual void setThresholdAcceptation(const double th)
void computeVVSCheckLevenbergMarquardtKlt(const unsigned int iter, const unsigned int nbInfos, const vpHomogeneousMatrix &cMoPrev, const vpColVector &error_prev, const vpHomogeneousMatrix &ctTc0_Prev, double &mu, bool &reStartFromLastIncrement)
bool useOgre
Use Ogre3d for visibility tests.
virtual void setLod(const bool useLod, const std::string &name="")
virtual void init(const vpImage< unsigned char > &I)
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
bool computeCovariance
Flag used to specify if the covariance matrix has to be computed or not.
bool firstInitialisation
Flag to specify whether the init method is called the first or not (specific calls to realize in this...
Class that defines what is a point.
vpCameraParameters cam
The camera parameters.
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
Map of camera transformation matrix between the current camera frame to the reference camera frame (c...
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
virtual void setReferenceCameraName(const std::string &referenceCameraName)
virtual std::map< std::string, vpKltOpencv > getKltOpencv() const
virtual std::map< std::string, std::vector< vpImagePoint > > getKltImagePoints() const
Implementation of an homography and operations on homographies.
void computeVVSInteractionMatrixAndResidu(unsigned int shift, vpColVector &R, vpMatrix &L, vpHomography &H, std::list< vpMbtDistanceKltPoints * > &kltPolygons_, std::list< vpMbtDistanceKltCylinder * > &kltCylinders_, const vpHomogeneousMatrix &ctTc0_)
Error that can be emited by the vpTracker class and its derivates.
vp_deprecated void init()
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
virtual void setClipping(const unsigned int &flags)
virtual vpHomogeneousMatrix getPose() const
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
bool useScanLine
Use Scanline for visibility tests.
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
virtual std::map< std::string, std::vector< cv::Point2f > > getKltPoints() const
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
unsigned int maskBorder
Erosion of the mask.
Generic class defining intrinsic camera parameters.
virtual void setAngleAppear(const double &a)
virtual void setAngleAppear(const double &a)
Implementation of a velocity twist matrix and operations on such kind of matrices.
vpMbtOptimizationMethod m_optimizationMethod
Optimization method used.
std::string m_referenceCameraName
Name of the reference camera.
double angleAppears
Angle used to detect a face appearance.
virtual ~vpMbKltMultiTracker()
std::list< vpMbtDistanceKltCylinder * > kltCylinders
virtual void postTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, unsigned int > &mapOfNbInfos, vpColVector &w_klt)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static double rad(double deg)
double threshold_outlier
Threshold below which the weight associated to a point to consider this one as an outlier...
std::map< std::string, vpMbKltTracker * > m_mapOfKltTrackers
Map of Model-based klt trackers.
virtual void setKltOpencv(const vpKltOpencv &t)
virtual std::map< std::string, std::map< int, vpImagePoint > > getKltImagePointsWithId() const
virtual void setNearClippingDistance(const double &dist)
double lambda
The gain of the virtual visual servoing stage.
virtual void setCameraParameters(const vpCameraParameters &camera)
virtual void setOgreVisibilityTest(const bool &v)
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
std::list< vpMbtDistanceCircle * > circles_disp
Vector of the circles used here only to display the full model.
bool displayFeatures
If true, the features are displayed.
Implementation of column vector and the associated operations.
virtual void loadModel(const std::string &modelFile, const bool verbose=false)
Implementation of a pose vector and operations on poses.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
vpHomogeneousMatrix inverse() const
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
Contains an M-Estimator and various influence function.
double angleDisappears
Angle used to detect a face disappearance.
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setClipping(const unsigned int &flags)
virtual void initClick(const vpImage< unsigned char > &I, const std::vector< vpPoint > &points3D_list, const std::string &displayFile="")
void computeVVSCovariance(const vpColVector &w_true, const vpHomogeneousMatrix &cMoPrev, const vpMatrix &L_true, const vpMatrix &LVJ_true)
unsigned int clippingFlag
Flags specifying which clipping to used.
virtual void setFarClippingDistance(const double &dist)
virtual void setMaskBorder(const unsigned int &e)
virtual void resetTracker()
vpHomogeneousMatrix c0Mo
Initial pose.
virtual std::map< std::string, unsigned int > getMultiNbPolygon() const
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
virtual void setScanLineVisibilityTest(const bool &v)
void resize(const unsigned int i, const bool flagNullify=true)
vpColVector m_w
Weights used in the robust scheme.
virtual void setNearClippingDistance(const double &dist)