Skip to content

Commit

Permalink
fixed opencv version issue for AKAZE,LATCH,LSD,BLD features and updat…
Browse files Browse the repository at this point in the history
…ed authors file
  • Loading branch information
raghavendersahdev authored and jlblancoc committed Sep 2, 2017
1 parent 7db1fa3 commit c7ed37f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 135 deletions.
4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,9 @@ the GitHub contributors page (https://github.com/MRPT/mrpt/graphs/contributors).
* Alisa Chukaeva (LisGein), Moscow Technological University (2017)
- The application robot-map-gui.

* Raghavender Sahdev, York University, Canada (GSoC 2017) https://github.com/raghavendersahdev
- The application benchmarking-image-features
- added files in the mrpt/libs/vision (detectors: AKAZE, LSD line detectors; descriptors: LATCH, BLD)

Several bug reports have been provided from MRPT users world-wide. We kindly thank all of
them for this valuable feedback, and they are usually mentioned in changelogs.
1 change: 1 addition & 0 deletions doc/man-pages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ IF (PROG_GZIP AND PROG_POD2MAN)

CREATE_MANPAGE_PROJECT(DifOdometry-Datasets)
CREATE_MANPAGE_PROJECT(DifOdometry-Camera)
CREATE_MANPAGE_PROJECT(robot-map-gui)

CREATE_MANPAGE_PROJECT(benchmarking-image-features)
ENDIF (PROG_GZIP AND PROG_POD2MAN)
78 changes: 22 additions & 56 deletions libs/vision/src/CFeatureExtraction_AKAZE.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
//
// Created by raghavender on 28/06/17.
//
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| http://www.mrpt.org/ |
| |
| Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
| See: http://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See details in http://www.mrpt.org/License |
+------------------------------------------------------------------------+ */

#include <opencv2/features2d.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
/*---------------------------------------------------------------
APPLICATION: CFeatureExtraction
FILE: CFeatureExtraction_AKAZE.cpp
AUTHOR: Raghavender Sahdev <[email protected]>
---------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "opencv2/core.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"

#include <vector>
#include <iostream>


#include "vision-precomp.h" // Precompiled headers
// Universal include for all versions of OpenCV
#include <mrpt/otherlibs/do_opencv_includes.h>

#include "vision-precomp.h" // Precompiled headers
#include <mrpt/system/os.h>
#include <mrpt/vision/CFeatureExtraction.h> // important import
#include <mrpt/utils/CMemoryStream.h>
#include <mrpt/otherlibs/do_opencv_includes.h>


using namespace mrpt::vision;
using namespace mrpt::utils;

using namespace mrpt::math;
using namespace mrpt;

using namespace std;
using namespace cv;



void CFeatureExtraction::extractFeaturesAKAZE(
const mrpt::utils::CImage & inImg,
Expand All @@ -48,28 +43,19 @@ void CFeatureExtraction::extractFeaturesAKAZE(
MRPT_UNUSED_PARAM(ROI);
MRPT_START
#if MRPT_HAS_OPENCV
# if MRPT_OPENCV_VERSION_NUM < 0x210
THROW_EXCEPTION("This function requires OpenCV > 2.1.0")
# if MRPT_OPENCV_VERSION_NUM < 0x300
THROW_EXCEPTION("This function requires OpenCV > 3.0.0")
# else

using namespace cv;

vector<KeyPoint> cv_feats; // The opencv keypoint output vector

// Make sure we operate on a gray-scale version of the image:
const CImage inImg_gray( inImg, FAST_REF_OR_CONVERT_TO_GRAY );



#if MRPT_OPENCV_VERSION_NUM >= 0x211

// cv::Mat *mask ;
// if( _mask )
// mask = static_cast<cv::Mat*>(_mask);
#if MRPT_OPENCV_VERSION_NUM >= 0x300

const Mat theImg = cvarrToMat( inImg_gray.getAs<IplImage>() );


Ptr<AKAZE> akaze = AKAZE::create(options.AKAZEOptions.descriptor_type , options.AKAZEOptions.descriptor_size ,
options.AKAZEOptions.descriptor_channels , options.AKAZEOptions.threshold , options.AKAZEOptions.nOctaves ,
options.AKAZEOptions.nOctaveLayers , options.AKAZEOptions.diffusivity);
Expand All @@ -80,13 +66,6 @@ void CFeatureExtraction::extractFeaturesAKAZE(
const size_t N = cv_feats.size();

#endif

// Now:
// 1) Sort them by "response": It's ~100 times faster to sort a list of
// indices "sorted_indices" than sorting directly the actual list of features "cv_feats"
//std::vector<size_t> sorted_indices(N);
//for (size_t i=0;i<N;i++) sorted_indices[i]=i;
//std::sort( sorted_indices.begin(), sorted_indices.end(), KeypointResponseSorter<vector<KeyPoint> >(cv_feats) );
// sort the AKAZE features by line length
for(int i=0; i<N ;i++)
{
Expand All @@ -101,16 +80,6 @@ void CFeatureExtraction::extractFeaturesAKAZE(
}
}

// 2) Filter by "min-distance" (in options.FASTOptions.min_distance) // not REQUIRED FOR LSD FEATYRES
// 3) Convert to MRPT CFeatureList format.
// Steps 2 & 3 are done together in the while() below.
// The "min-distance" filter is done by means of a 2D binary matrix where each cell is marked when one
// feature falls within it. This is not exactly the same than a pure "min-distance" but is pretty close
// and for large numbers of features is much faster than brute force search of kd-trees.
// (An intermediate approach would be the creation of a mask image updated for each accepted feature, etc.)




unsigned int nMax = (nDesiredFeatures!=0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
const int offset = (int)this->options.patchSize/2 + 1;
Expand All @@ -126,7 +95,7 @@ void CFeatureExtraction::extractFeaturesAKAZE(

while( cont != nMax && i!=N )
{
// Take the next feature fromt the ordered list of good features:
// Take the next feature from the ordered list of good features:
const KeyPoint &kp = cv_feats[i];
i++;

Expand Down Expand Up @@ -164,11 +133,8 @@ void CFeatureExtraction::extractFeaturesAKAZE(
++cont;
//cout << ft->x << " " << ft->y << endl;
}
//feats.resize( cont ); // JL: really needed???

# endif
#endif
MRPT_END


}
54 changes: 24 additions & 30 deletions libs/vision/src/CFeatureExtraction_LATCH.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
//
// Created by raghavender on 28/06/17.
//




#include <vector>
#include <iostream>

/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| http://www.mrpt.org/ |
| |
| Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
| See: http://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See details in http://www.mrpt.org/License |
+------------------------------------------------------------------------+ */

/*---------------------------------------------------------------
APPLICATION: CFeatureExtraction
FILE: CFeatureExtraction_LATCH.cpp
AUTHOR: Raghavender Sahdev <[email protected]>
---------------------------------------------------------------*/

#include "vision-precomp.h" // Precompiled headers

#include <mrpt/system/os.h>
#include <mrpt/vision/CFeatureExtraction.h> // important import
#include <mrpt/utils/CMemoryStream.h>
#include <mrpt/otherlibs/do_opencv_includes.h>
// Universal include for all versions of OpenCV
#include <mrpt/otherlibs/do_opencv_includes.h>

#ifdef HAVE_OPENCV_NONFREE //MRPT_HAS_OPENCV_NONFREE
# include <opencv2/nonfree/nonfree.hpp>
#endif
#ifdef HAVE_OPENCV_FEATURES2D
# include <opencv2/features2d/features2d.hpp>
# include <opencv2/line_descriptor.hpp>
#endif

#ifdef HAVE_OPENCV_XFEATURES2D
# include <opencv2/xfeatures2d.hpp>
#endif



#ifdef HAVE_OPENCV_FEATURES2D
# include <opencv2/line_descriptor.hpp>
using namespace cv::line_descriptor;
#endif


using namespace mrpt::vision;
using namespace mrpt::utils;

using namespace mrpt::math;
using namespace mrpt;

using namespace std;
#if MRPT_HAS_OPENCV
# if MRPT_OPENCV_VERSION_NUM>=0x211
using namespace cv;
# endif
#endif



/************************************************************************************************
* internal_computeLATCHDescriptors
Expand All @@ -54,14 +48,15 @@ void CFeatureExtraction::internal_computeLATCHDescriptors(
const mrpt::utils::CImage &in_img,
CFeatureList &in_features) const
{
//function is tested with opencv 3.1
MRPT_START
#if MRPT_HAS_OPENCV
# if MRPT_OPENCV_VERSION_NUM < 0x210
THROW_EXCEPTION("This function requires OpenCV > 2.1.0")
# if MRPT_OPENCV_VERSION_NUM < 0x300
THROW_EXCEPTION("This function requires OpenCV > 3.0.0")
# else

using namespace cv;

//cout << "I am in LATCH descriptor" << endl;
if (in_features.empty()) return;

const size_t n_feats = in_features.size();
Expand All @@ -84,7 +79,6 @@ void CFeatureExtraction::internal_computeLATCHDescriptors(


Ptr<xfeatures2d::LATCH> latch = xfeatures2d::LATCH::create(options.LATCHOptions.bytes, options.LATCHOptions.rotationInvariance, options.LATCHOptions.half_ssd_size);

latch->compute(cvImg, cv_feats, cv_descs);

// -----------------------------------------------------------------
Expand Down
Loading

0 comments on commit c7ed37f

Please sign in to comment.