32 mRelocaliser(mMap, mCamera),
44 template <
typename T>
string tostr(
string w,
const T& t) {
76 std::cout <<
"Tracker resetting..." << std::endl;
105 std::cout <<
"Tracker reset." << std::endl;
156 std::ostringstream points;
205 LOGV(
LOG_TAG,
"Info_Key-Frame: %s",
"Adding key-frame");
221 float heading, attitude, bank = 0;
223 std::ostringstream data;
233 cout <<
"Track for initial map"<<endl;
256 if (m(1,0) > 0.998) {
257 heading = atan2(m(0,2),m(2,2));
262 if (m(1,0) < -0.998) {
263 heading = atan2(m(0,2),m(2,2));
268 heading = atan2(-m(2,0),m(0,0));
269 bank = atan2(-m(1,2),m(1,1));
270 attitude = asin(m(1,0));
300 ((
Tracker*) ptr)->mvQueuedCommands.push_back(c);
306 if(sCommand==
"Reset")
313 if(sCommand==
"KeyPress")
315 if(sParams ==
"Space")
319 else if(sParams ==
"r")
323 else if(sParams ==
"q" || sParams ==
"Escape")
329 if((sCommand==
"PokeTracker"))
336 cout <<
"! Tracker::GUICommandHandler: unhandled command "<< sCommand << endl;
364 mMessageForUser <<
"Point camera at planar scene and press spacebar to start tracking for initial map." << endl;
381 clock_t startMapMaker, stopMapMaker;
383 startMapMaker = clock();
387 vector<pair<ImageRef, ImageRef> > vMatches;
389 vMatches.push_back(pair<ImageRef, ImageRef>(i->irInitialPos,
395 LOGV(
LOG_TAG,
"MapMaker.InitFromStereo: Failed, Tracker: Reset()");
400 stopMapMaker = clock();
401 std::ostringstream message;
402 message <<
"MapMaker: number of corners : "<< numOfCorners <<
"::Number of trails: "<< vMatches.size()<<
":: Duration of initFromStereo: " << (float)(stopMapMaker - startMapMaker)/CLOCKS_PER_SEC*1000 << endl;
408 mMessageForUser <<
"Translate the camera slowly sideways, and press spacebar again to perform stereo init." << endl;
417 vector<pair<double,ImageRef> > vCornersAndSTScores;
423 vCornersAndSTScores.push_back(pair<double,ImageRef>(-1.0 * c.
dSTScore, c.
irLevelPos));
425 sort(vCornersAndSTScores.begin(), vCornersAndSTScores.end());
427 for(
unsigned int i = 0; i<vCornersAndSTScores.size() && nToAdd > 0; i++)
453 list<Trail>::iterator next = i; next++;
464 bFound = BackwardsPatch.
FindPatch(irBackWardsFound, lPreviousFrame.
im, 10, lPreviousFrame.
vCorners);
465 if((irBackWardsFound - irStart).mag_squared() > 2)
499 for(
int i=0; i<
LEVELS; i++)
503 vector<TrackerData*> avPVS[
LEVELS];
504 for(
int i=0; i<
LEVELS; i++)
505 avPVS[i].reserve(500);
536 for(
int i=0; i<
LEVELS; i++)
537 random_shuffle(avPVS[i].begin(), avPVS[i].end());
541 vector<TrackerData*> vNextToSearch;
542 vector<TrackerData*> vIterationSet;
552 unsigned int nCoarseMax = gvnCoarseMax;
553 unsigned int nCoarseRange = gvnCoarseRange;
558 bool bTryCoarse =
true;
559 if(gvnCoarseDisabled ||
574 if(bTryCoarse && avPVS[LEVELS-1].size() + avPVS[LEVELS-2].size() > gvnCoarseMin )
580 if(avPVS[LEVELS-1].size() <= nCoarseMax)
582 vNextToSearch = avPVS[LEVELS-1];
583 avPVS[LEVELS-1].clear();
587 for(
unsigned int i=0; i<nCoarseMax; i++)
588 vNextToSearch.push_back(avPVS[LEVELS-1][i]);
589 avPVS[LEVELS-1].erase(avPVS[LEVELS-1].begin(), avPVS[LEVELS-1].begin() + nCoarseMax);
593 if(vNextToSearch.size() < nCoarseMax)
595 unsigned int nMoreCoarseNeeded = nCoarseMax - vNextToSearch.size();
596 if(avPVS[LEVELS-2].size() <= nMoreCoarseNeeded)
598 vNextToSearch = avPVS[LEVELS-2];
599 avPVS[LEVELS-2].clear();
603 for(
unsigned int i=0; i<nMoreCoarseNeeded; i++)
604 vNextToSearch.push_back(avPVS[LEVELS-2][i]);
605 avPVS[LEVELS-2].erase(avPVS[LEVELS-2].begin(), avPVS[LEVELS-2].begin() + nMoreCoarseNeeded);
609 unsigned int nFound =
SearchForPoints(vNextToSearch, nCoarseRange, gvnCoarseSubPixIts);
610 vIterationSet = vNextToSearch;
611 if(nFound >= gvnCoarseMin)
614 for(
int iter = 0; iter<10; iter++)
618 for(
unsigned int i=0; i<vIterationSet.size(); i++)
619 if(vIterationSet[i]->bFound)
622 for(
unsigned int i=0; i<vIterationSet.size(); i++)
623 if(vIterationSet[i]->bFound)
624 vIterationSet[i]->CalcJacobian();
625 double dOverrideSigma = 0.0;
629 dOverrideSigma = 1.0;
650 for(
unsigned int i=0; i<avPVS[l].size(); i++)
653 for(
unsigned int i=0; i<avPVS[l].size(); i++)
654 vIterationSet.push_back(avPVS[l][i]);
658 vNextToSearch.clear();
659 for(
int l=LEVELS - 2; l>=0; l--)
660 for(
unsigned int i=0; i<avPVS[l].size(); i++)
661 vNextToSearch.push_back(avPVS[l][i]);
666 int nFinePatchesToUse = gvnMaxPatchesPerFrame - vIterationSet.size();
667 if(nFinePatchesToUse < 0)
668 nFinePatchesToUse = 0;
669 if((
int) vNextToSearch.size() > nFinePatchesToUse)
671 random_shuffle(vNextToSearch.begin(), vNextToSearch.end());
672 vNextToSearch.resize(nFinePatchesToUse);
677 for(
unsigned int i=0; i<vNextToSearch.size(); i++)
683 for(
unsigned int i=0; i<vNextToSearch.size(); i++)
684 vIterationSet.push_back(vNextToSearch[i]);
688 v6LastUpdate =
Zeros;
689 for(
int iter = 0; iter<10; iter++)
691 bool bNonLinearIteration;
693 if(iter == 0 || iter == 4 || iter == 9)
694 bNonLinearIteration =
true;
696 bNonLinearIteration =
false;
700 if(bNonLinearIteration)
702 for(
unsigned int i=0; i<vIterationSet.size(); i++)
703 if(vIterationSet[i]->bFound)
708 for(
unsigned int i=0; i<vIterationSet.size(); i++)
709 if(vIterationSet[i]->bFound)
710 vIterationSet[i]->LinearUpdate(v6LastUpdate);
714 if(bNonLinearIteration)
715 for(
unsigned int i=0; i<vIterationSet.size(); i++)
716 if(vIterationSet[i]->bFound)
717 vIterationSet[i]->CalcJacobian();
720 double dOverrideSigma = 0.0;
722 dOverrideSigma = 16.0;
728 v6LastUpdate = v6Update;
739 for(vector<TrackerData*>::iterator it = vIterationSet.begin();
740 it!= vIterationSet.end();
747 m.
nLevel = (*it)->nSearchLevel;
757 for(vector<TrackerData*>::iterator it = vIterationSet.begin();
758 it!= vIterationSet.end();
762 double z = (*it)->v3Cam[2];
779 for(
unsigned int i=0; i<vTD.size(); i++)
814 if(!bSubPixConverges)
844 if(gvsEstimator ==
"Tukey")
846 else if(gvsEstimator ==
"Cauchy")
848 else if(gvsEstimator ==
"Huber")
852 cout <<
"Invalid TrackerMEstimator, choices are Tukey, Cauchy, Huber" << endl;
854 gvsEstimator =
"Tukey";
859 vector<double> vdErrorSquared;
860 for(
unsigned int f=0; f<vTD.size(); f++)
870 if(vdErrorSquared.size() == 0)
874 double dSigmaSquared;
875 if(dOverrideSigma > 0)
876 dSigmaSquared = dOverrideSigma;
881 else if(nEstimator == 1)
891 for(
unsigned int f=0; f<vTD.size(); f++)
897 double dErrorSq = v2 * v2;
902 else if(nEstimator == 1)
938 v6Velocity.slice<3,3>() =
mv6SBIRot.slice<3,3>();
977 int nTotalAttempted = 0;
979 int nLargeAttempted = 0;
982 for(
int i=0; i<
LEVELS; i++)
990 if(nTotalFound == 0 || nTotalAttempted == 0)
994 double dTotalFracFound = (double) nTotalFound / nTotalAttempted;
995 double dLargeFracFound;
996 if(nLargeAttempted > 10)
997 dLargeFracFound = (double) nLargeFound / nLargeAttempted;
999 dLargeFracFound = dTotalFracFound;
1005 if(dTotalFracFound > gvdQualityGood)
1007 else if(dLargeFracFound < gvdQualityLost)
1035 pair<SE2<>,
double> result_pair;
1045 std::ostringstream corners;
1052 return corners.str();
Tracker(CVD::ImageRef irVideoSize, const ATANCamera &c, Map &m, MapMaker &mm)
static double Weight(double dErrorSquared, double dSigmaSquared)
const double TrackerTrackingQualityLost
void GetDerivsUnsafe(ATANCamera &Cam)
const int TrackerCoarseMax
Vector< 6 > CalcPoseUpdate(std::vector< TrackerData * > vTD, double dOverrideSigma=0.0, bool bMarkOutliers=false)
bool IsDistanceToNearestKeyFrameExcessive(KeyFrame &kCurrent)
#define LOGV(LOG_TAG,...)
const int TrackerCoarseRange
std::pair< SE2<>, double > IteratePosRelToTarget(SmallBlurryImage &other, int nIterations=10)
const double TrackerCoarseMinVelocity
SmallBlurryImage * mpSBILastFrame
const int TrackerMiniPatchMaxSSD
int nMEstimatorOutlierCount
bool FindPatchCoarse(CVD::ImageRef ir, KeyFrame &kf, unsigned int nRange)
SO3< Precision > & get_rotation()
Returns the rotation part of the transformation as a SO3.
std::vector< Command > mvQueuedCommands
static void GUICommandCallBack(void *ptr, std::string sCommand, std::string sParams)
void SampleFromImage(CVD::ImageRef irPos, CVD::BasicImage< CVD::byte > &im)
Vector< 6 > mv6CameraVelocity
const std::string TrackerMEstimator
static double Weight(double dErrorSquared, double dSigmaSquared)
CVD::ImageRef irCurrentPos
Matrix< 2, 6 > m26Jacobian
CVD::Image< CVD::byte > im
int SearchForPoints(std::vector< TrackerData * > &vTD, int nRange, int nFineIts)
void MakeSubPixTemplate()
void SendPoseToUnity(float r1, float r2, float r3, double t1, double t2, double t3)
Send pose to Unity3D
static double FindSigmaSquared(std::vector< double > &vdErrorSquared)
static double FindSigmaSquared(std::vector< double > &vdErrorSquared)
void add_mJ(Precision m, const Vector< Size, Precision, B2 > &J, Precision weight=1)
void TrailTracking_Start()
int CalcSearchLevelAndWarpMatrix(MapPoint &p, SE3<> se3CFromW, Matrix< 2 > &m2CamDerivs)
void SendStringToUnity(const char *st)
Send string to Unity3D
void GetEulerAnglesFromRotationMatrix(Matrix< 3, 3, double > &m, float &heading, float &attitude, float &bank)
double mdVelocityMagnitude
bool NeedNewKeyFrame(KeyFrame &kCurrent)
bool FindPatch(CVD::ImageRef &irPos, CVD::BasicImage< CVD::byte > &im, int nRange, std::vector< CVD::ImageRef > &vCorners, std::vector< int > *pvRowLUT=NULL)
std::string getVCorners()
void AddKeyFrame(KeyFrame &k)
static double Weight(double dErrorSquared, double dSigmaSquared)
Vector< 2 > GetSubPixPos()
double mdMSDScaledVelocityMagnitude
std::vector< MapPoint * > vpPoints
Vector< 2 > GetCoarsePosAsVector()
enum Tracker::@13 mnInitialStage
void AssessTrackingQuality()
void SetSendMessageToUnity(SendMessage sm)
Vector< Size, Precision > & get_mu()
Returns the update. With no prior, this is the result of .
void SendLogToUnity(const char *st)
Send string to Unity3D
const int TrackerUseRotationEstimator
bool IterateSubPixToConvergence(KeyFrame &kf, int nMaxIts)
std::string GetMessageForUser()
int MakeKeyFrame_Lite(CVD::BasicImage< CVD::byte > &im, int threshold)
const int TrackerDisableCoarse
CVD::ImageRef irInitialPos
std::vector< CVD::ImageRef > vCorners
const int DesiredNumberOfCorners
void GUICommandHandler(std::string sCommand, std::string sParams)
const bool SendArrayOfPointsForCornersTex
DetectionState currentState
std::vector< KeyFrame * > vpKeyFrames
SmallBlurryImage * mpSBIThisFrame
bool InitFromStereo(KeyFrame &kFirst, KeyFrame &kSecond, std::vector< std::pair< CVD::ImageRef, CVD::ImageRef > > &vMatches, SE3<> &se3CameraPos)
const double TrackerRotationEstimatorBlur
const bool UseNumberOfCornersAdjustment
Matrix< R, C, P > exp(const Matrix< R, C, P, B > &m)
std::ostringstream mMessageForUser
int TrailTracking_Advance()
void Project(const SE3<> &se3CFromW, ATANCamera &Cam)
bool mbUserPressedSpacebar
const int TrackerCoarseSubPixIts
bool in_image_with_border(const ImageRef &ir, int border) const
KeyFrame mPreviousFrameKF
const int TrackerCoarseMin
std::list< Trail > mlTrails
const int DesiredNumberOfCornersOffset
enum Tracker::@14 mTrackingQuality
ImageRef ir(const TooN::Vector< 2 > &v)
int nMEstimatorInlierCount
const int MaxInitialTrails
void TrackForInitialMap()
Vector< 3, Precision > & get_translation()
Returns the translation part of the transformation as a Vector.
Vector< 2 > v2Error_CovScaled
std::map< MapPoint *, Measurement > mMeasurements
void TrackFrame(CVD::Image< CVD::byte > &imFrame, uint hnd, bool bDraw)
int manMeasAttempted[LEVELS]
Vector< 1 > makeVector(double x1)
string tostr(string w, const T &t)
bool AttemptRecovery(KeyFrame &k)
void SetImageSize(Vector< 2 > v2ImageSize)
const int TrackerMaxPatchesPerFrame
bool mbJustRecoveredSoUseCoarse
static int mnHalfPatchSize
static Vector< 6, Precision > ln(const SE3 &se3)
void SendArrayOfPoints(int arrayOfPoint[], int size)
Send array of points to Unity3D
void add_prior(Precision val)
DetectionState GetCurrentDetectionState()
DetectionState
Enum for state of SLAM detection process.
void MakeTemplateCoarseCont(MapPoint &p)
std::vector< Candidate > vCandidates
static double FindSigmaSquared(std::vector< double > &vdErrorSquared)
int mnLastKeyFrameDropped
static Operator< Internal::Zero > Zeros
const double TrackerTrackingQualityGood
static CVD::ImageRef irImageSize
float RadiansToDegrees(float r)
static SE3 SE3fromSE2(SE2<> se2, ATANCamera camera)