17 #include <mrpt/otherlibs/do_opencv_includes.h>    36 template <
typename FEATLIST>
    38     const CImage& old_img, 
const CImage& new_img, FEATLIST& featureList)
    43     const unsigned int window_width =
    44         extra_params.getWithDefaultVal(
"window_width", 15);
    45     const unsigned int window_height =
    46         extra_params.getWithDefaultVal(
"window_height", 15);
    48     const int LK_levels = extra_params.getWithDefaultVal(
"LK_levels", 3);
    49     const int LK_max_iters = extra_params.getWithDefaultVal(
"LK_max_iters", 10);
    50     const int LK_epsilon = extra_params.getWithDefaultVal(
"LK_epsilon", 0.1);
    51     const float LK_max_tracking_error =
    52         extra_params.getWithDefaultVal(
"LK_max_tracking_error", 150.0f);
    59     const size_t img_width = old_img.
getWidth();
    60     const size_t img_height = old_img.
getHeight();
    62     const size_t nFeatures = featureList.size();  
    73         points[0] = 
reinterpret_cast<CvPoint2D32f*
>(
    75         points[1] = 
reinterpret_cast<CvPoint2D32f*
>(
    78         std::vector<char> 
status(nFeatures);
    80         for (
size_t i = 0; i < nFeatures; ++i)
    82             points[0][i].x = featureList.getFeatureX(i);
    83             points[0][i].y = featureList.getFeatureY(i);
    87         const IplImage* prev_gray_ipl = prev_gray.
getAs<IplImage>();
    88         const IplImage* cur_gray_ipl = cur_gray.
getAs<IplImage>();
    93         IplImage* pPyr = 
nullptr;
    94         IplImage* cPyr = 
nullptr;
    99             reinterpret_cast<float*
>(
mrpt_alloca(
sizeof(
float) * nFeatures));
   101         cvCalcOpticalFlowPyrLK(
   102             prev_gray_ipl, cur_gray_ipl, pPyr, cPyr, &
points[0][0],
   103             &
points[1][0], nFeatures, cvSize(window_width, window_height),
   104             LK_levels, &
status[0], track_error,
   106                 CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, LK_max_iters, LK_epsilon),
   109         cvReleaseImage(&pPyr);
   110         cvReleaseImage(&cPyr);
   112         for (
size_t i = 0; i < nFeatures; ++i)
   114             const bool trck_err_too_large =
   115                 track_error[i] > LK_max_tracking_error;
   117             if (
status[i] == 1 && !trck_err_too_large && 
points[1][i].
x > 0 &&
   122                 featureList.setFeatureXf(i, 
points[1][i].
x);
   123                 featureList.setFeatureYf(i, 
points[1][i].
y);
   128                 featureList.setFeatureX(i, -1);
   129                 featureList.setFeatureY(i, -1);
   130                 featureList.setTrackStatus(
   140         featureList.mark_as_outdated();
   144     THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   153     trackFeatures_impl_templ<CFeatureList>(old_img, new_img, featureList);
   160     trackFeatures_impl_templ<TSimpleFeatureList>(old_img, new_img, featureList);
   167     trackFeatures_impl_templ<TSimpleFeaturefList>(
   168         old_img, new_img, featureList);
 const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. 
 
#define THROW_EXCEPTION(msg)
 
size_t getHeight() const override
Returns the height of the image in pixels. 
 
virtual void trackFeatures_impl(const mrpt::img::CImage &old_img, const mrpt::img::CImage &new_img, vision::CFeatureList &inout_featureList) override
This version falls back to the version with TSimpleFeatureList if the derived class does not implemen...
 
Feature correctly tracked. 
 
GLsizei const GLfloat * points
 
#define ASSERT_(f)
Defines an assertion mechanism. 
 
size_t getWidth() const override
Returns the width of the image in pixels. 
 
Classes for computer vision, detectors, features, etc. 
 
void trackFeatures_impl_templ(const mrpt::img::CImage &old_img, const mrpt::img::CImage &new_img, FEATLIST &inout_featureList)
Track a set of features from old_img -> new_img using sparse optimal flow (classic KL method) Optiona...
 
#define mrpt_alloca(nBytes)
In platforms and compilers with support to "alloca", allocate a memory block on the stack; if alloca ...
 
A list of visual features, to be used as output by detectors, as input/output by trackers, etc. 
 
Unable to track this feature (mismatch is too high for the given tracking window: lack of texture...
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
#define mrpt_alloca_free(mem_block)
This method must be called to "free" each memory block allocated with "system::alloca": If the block ...
 
Feature fell Out Of Bounds (out of the image limits, too close to image borders) 
 
A class for storing images as grayscale or RGB bitmaps.