diff --git a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.cpp b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.cpp index 49d8dd5..cf1f5ff 100644 --- a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.cpp +++ b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.cpp @@ -11,6 +11,8 @@ extern const int markerTemplateWidth = 15; ///< Width in pixels of image patches extern const int maxLevel = 3; ///< Maximum number of levels in optical flow image pyramid. extern const cv::Size winSize(31, 31); extern const cv::TermCriteria termcrit(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 20, 0.03); +extern const int searchRadius = 15; +extern const int match_method = cv::TM_SQDIFF_NORMED; extern const double featureDetectPyramidLevel = 1.05f; ///> Scale factor applied to image pyramid to determine image to perform feature matching upon. extern const int featureBorder = 8; diff --git a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp index e40a8fe..3d963af 100644 --- a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp +++ b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp @@ -12,7 +12,7 @@ class WebARKitTracker::WebARKitTrackerImpl { TrackerVisualization _trackViz; WebARKitTrackerImpl() - : corners(4), initialized(false), output(17, 0.0), _valid(false), _isDetected(false), _isTracking(false), + : corners(4), initialized(false), output(17, 0.0), _valid(false), _currentlyTrackedMarkers(0), _frameCount(0), _isDetected(false), _isTracking(false), numMatches(0), minNumMatches(MIN_NUM_MATCHES), _nn_match_ratio(0.7f),_trackVizActive(false), _trackViz(TrackerVisualization()) { m_camMatrix = cv::Matx33d::zeros(); m_distortionCoeff = cv::Mat::zeros(4, 1, cv::DataType::type); @@ -56,6 +56,7 @@ class WebARKitTracker::WebARKitTrackerImpl { _pyramid.clear(); _prevPyramid.clear(); + _currentlyTrackedMarkers = 0; } template void initTracker(T refData, size_t refCols, size_t refRows, ColorSpace colorSpace) { @@ -165,8 +166,6 @@ class WebARKitTracker::WebARKitTrackerImpl { _isDetected = false; - cv::Mat _image; - cv::Mat frameDescr; std::vector frameKeyPts; bool valid; @@ -412,9 +411,9 @@ class WebARKitTracker::WebARKitTrackerImpl { if (_trackVizActive) _trackViz.templateMatching.failedBoundsTestCount++; } } - bool gotHomography = UpdateTrackableHomography(trackableId, finalTemplatePoints, finalTemplateMatchPoints); + bool gotHomography = updateTrackableHomography(trackableId, finalTemplatePoints, finalTemplateMatchPoints); if (!gotHomography) { - //_trackables[trackableId]._isTracking = false; + // _trackables[trackableId]._isTracking = false; // _trackables[trackableId]._isDetected = false; _isTracking = false; _isDetected = false; @@ -488,7 +487,8 @@ class WebARKitTracker::WebARKitTrackerImpl { int i = 0; if (_isDetected) { WEBARKIT_LOGi("Start tracking!\n"); - if (_prevPyramid.size() > 0) { + if (_frameCount > 0 && _prevPyramid.size() > 0) { + //if (_prevPyramid.size() > 0) { // std::cout << "Starting Optical Flow" << std::endl; //std::vector warpedPoints; // perspectiveTransform(framePts, warpedPoints, m_H); @@ -523,6 +523,7 @@ class WebARKitTracker::WebARKitTrackerImpl { WEBARKIT_LOG("Marker detected : %s\n", _isDetected ? "true" : "false"); swapImagePyramid(); + _frameCount++; } bool homographyValid(cv::Mat& H) { @@ -653,7 +654,7 @@ class WebARKitTracker::WebARKitTrackerImpl { _trackViz.bounds[i][1] = _bBoxTransformed[i].y; } } - //_currentlyTrackedMarkers++; + _currentlyTrackedMarkers++; } } } @@ -692,7 +693,7 @@ class WebARKitTracker::WebARKitTrackerImpl { if (!updateTrackableHomography(trackableId, filteredTrackablePoints, filteredTrackedPoints)) { _isDetected = false; _isTracking = false; - //_currentlyTrackedMarkers--; + _currentlyTrackedMarkers--; return false; } @@ -871,6 +872,12 @@ class WebARKitTracker::WebARKitTrackerImpl { return warpedPoints; } + cv::Mat _image; + + int _currentlyTrackedMarkers; + + int _frameCount; + bool _valid; bool _isDetected; diff --git a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h index 876b085..c159c4f 100644 --- a/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h +++ b/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h @@ -19,6 +19,8 @@ extern const int markerTemplateWidth; ///< Width in pixels of image patches used extern const int maxLevel; ///< Maximum number of levels in optical flow image pyramid. extern const cv::Size winSize; extern const cv::TermCriteria termcrit; +extern const int searchRadius; +extern const int match_method; extern const double featureDetectPyramidLevel; ///> Scale factor applied to image pyramid to determine image to perform feature matching upon. extern const int featureBorder; extern const cv::Size blurSize;