Skip to content

Commit

Permalink
Fixed build with OpenCV 3 CUDA (issue #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
matlabbe committed Jul 10, 2015
1 parent dd14e5e commit 4b5da36
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 302 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENDIF()
#######################
# VERSION
#######################
SET(PROJECT_VERSION 0.5.1)
SET(PROJECT_VERSION "0.5.1")
SET(PROJECT_PREFIX find_object)

STRING(REGEX MATCHALL "[0-9]" PROJECT_VERSION_PARTS "${PROJECT_VERSION}")
Expand Down Expand Up @@ -232,6 +232,7 @@ IF(NOT CATKIN_BUILD)
MESSAGE(STATUS "Info :")
MESSAGE(STATUS " CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS " CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS " PROJECT_VERSION = ${PROJECT_VERSION}")

IF(OpenCV_VERSION_MAJOR EQUAL 2)
IF(OPENCV_NONFREE_FOUND)
Expand Down
7 changes: 3 additions & 4 deletions include/find_object/FindObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ namespace find_object {

class ObjSignature;
class Vocabulary;
class KeypointDetector;
class DescriptorExtractor;
class Feature2D;

class FINDOBJECT_EXP FindObject : public QObject
{
Expand Down Expand Up @@ -104,8 +103,8 @@ public Q_SLOTS:
Vocabulary * vocabulary_;
QMap<int, cv::Mat> objectsDescriptors_;
QMap<int, int> dataRange_; // <last id of object's descriptor, id>
KeypointDetector * detector_;
DescriptorExtractor * extractor_;
Feature2D * detector_;
Feature2D * extractor_;
bool sessionModified_;
bool keepImagesInRAM_;
};
Expand Down
52 changes: 26 additions & 26 deletions include/find_object/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace find_object {

class KeypointDetector;
class DescriptorExtractor;
class GPUFeature2D;
class Feature2D;

typedef QMap<QString, QVariant> ParametersMap; // Key, value
typedef QMap<QString, QString> ParametersType; // Key, type
Expand Down Expand Up @@ -107,7 +105,7 @@ class FINDOBJECT_EXP Settings
PARAMETER(Camera, 1deviceId, int, 0, "Device ID (default 0).");
PARAMETER(Camera, 2imageWidth, int, 0, "Image width (0 means default width from camera).");
PARAMETER(Camera, 3imageHeight, int, 0, "Image height (0 means default height from camera).");
PARAMETER(Camera, 4imageRate, double, 2.0, "Image rate in Hz (0 Hz means as fast as possible)."); // Hz
PARAMETER(Camera, 4imageRate, double, 10.0, "Image rate in Hz (0 Hz means as fast as possible)."); // Hz
PARAMETER(Camera, 5mediaPath, QString, "", "Video file or directory of images. If set, the camera is not used. See General->videoFormats and General->imageFormats for available formats.");
PARAMETER(Camera, 6useTcpCamera, bool, false, "Use TCP/IP input camera.");
PARAMETER(Camera, 8port, int, 0, "The images server's port when useTcpCamera is checked. Only one client at the same time is allowed.");
Expand Down Expand Up @@ -140,7 +138,8 @@ class FINDOBJECT_EXP Settings
PARAMETER(Feature2D, Fast_threshold, int, 10, "Threshold on difference between intensity of the central pixel and pixels of a circle around this pixel.");
PARAMETER(Feature2D, Fast_nonmaxSuppression, bool, true, "If true, non-maximum suppression is applied to detected corners (keypoints).");
PARAMETER(Feature2D, Fast_gpu, bool, false, "GPU-FAST: Use GPU version of FAST. This option is enabled only if OpenCV is built with CUDA and GPUs are detected.");
PARAMETER(Feature2D, Fast_keypointsRatio, double, 0.05, "Used with FAST GPU.");
PARAMETER(Feature2D, Fast_keypointsRatio, double, 0.05, "Used with FAST GPU (OpenCV 2).");
PARAMETER(Feature2D, Fast_maxNpoints, int, 5000, "Used with FAST GPU (OpenCV 3).");

PARAMETER(Feature2D, AGAST_threshold, int, 10, "Threshold on difference between intensity of the central pixel and pixels of a circle around this pixel.");
PARAMETER(Feature2D, AGAST_nonmaxSuppression, bool, true, "If true, non-maximum suppression is applied to detected corners (keypoints).");
Expand Down Expand Up @@ -173,6 +172,7 @@ class FINDOBJECT_EXP Settings
PARAMETER(Feature2D, ORB_scoreType, int, 0, "The default HARRIS_SCORE=0 means that Harris algorithm is used to rank features (the score is written to KeyPoint::score and is used to retain best nfeatures features); FAST_SCORE=1 is alternative value of the parameter that produces slightly less stable keypoints, but it is a little faster to compute.");
PARAMETER(Feature2D, ORB_patchSize, int, 31, "size of the patch used by the oriented BRIEF descriptor. Of course, on smaller pyramid layers the perceived image area covered by a feature will be larger.");
PARAMETER(Feature2D, ORB_gpu, bool, false, "GPU-ORB: Use GPU version of ORB. This option is enabled only if OpenCV is built with CUDA and GPUs are detected.");
PARAMETER(Feature2D, ORB_blurForDescriptor, bool, false, "GPU-ORB: blurForDescriptor parameter (OpenCV 3).");

PARAMETER(Feature2D, MSER_delta, int, 5, "");
PARAMETER(Feature2D, MSER_minArea, int, 60, "");
Expand Down Expand Up @@ -318,8 +318,8 @@ class FINDOBJECT_EXP Settings
static void resetParameter(const QString & key) {if(defaultParameters_.contains(key)) parameters_.insert(key, defaultParameters_.value(key));}
static QVariant getParameter(const QString & key) {return parameters_.value(key, QVariant());}

static KeypointDetector * createKeypointDetector();
static DescriptorExtractor * createDescriptorExtractor();
static Feature2D * createKeypointDetector();
static Feature2D * createDescriptorExtractor();

static QString currentDescriptorType();
static QString currentDetectorType();
Expand All @@ -344,36 +344,36 @@ class FINDOBJECT_EXP Settings
static QString iniPath_;
};

class KeypointDetector
class Feature2D
{
public:
KeypointDetector(cv::Ptr<cv::FeatureDetector> & featureDetector);
KeypointDetector(GPUFeature2D * gpuFeature2D);
virtual ~KeypointDetector();
#if CV_MAJOR_VERSION < 3
Feature2D(cv::Ptr<cv::FeatureDetector> featureDetector);
Feature2D(cv::Ptr<cv::DescriptorExtractor> descriptorExtractor);
#endif
Feature2D(cv::Ptr<cv::Feature2D> feature2D);
Feature2D() {}
virtual ~Feature2D() {}

void detect(const cv::Mat & image,
virtual void detect(const cv::Mat & image,
std::vector<cv::KeyPoint> & keypoints,
const cv::Mat & mask = cv::Mat());

private:
cv::Ptr<cv::FeatureDetector> featureDetector_;
GPUFeature2D * gpuFeature2D_;
};

class DescriptorExtractor
{
public:
DescriptorExtractor(cv::Ptr<cv::DescriptorExtractor> & descriptorExtractor);
DescriptorExtractor(GPUFeature2D * gpuFeature2D);
virtual ~DescriptorExtractor();

void compute(const cv::Mat & image,
virtual void compute(const cv::Mat & image,
std::vector<cv::KeyPoint> & keypoints,
cv::Mat & descriptors);

virtual void detectAndCompute(const cv::Mat & image,
std::vector<cv::KeyPoint> & keypoints,
cv::Mat & descriptors,
const cv::Mat & mask = cv::Mat());

private:
#if CV_MAJOR_VERSION < 3
cv::Ptr<cv::FeatureDetector> featureDetector_;
cv::Ptr<cv::DescriptorExtractor> descriptorExtractor_;
GPUFeature2D * gpuFeature2D_;
#endif
cv::Ptr<cv::Feature2D> feature2D_;
};

} // namespace find_object
Expand Down
7 changes: 3 additions & 4 deletions src/AddObjectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ namespace find_object {
class ObjWidget;
class Camera;
class KeypointItem;
class KeypointDetector;
class DescriptorExtractor;
class Feature2D;
class ObjSignature;

class AddObjectDialog : public QDialog {
Expand Down Expand Up @@ -78,8 +77,8 @@ private Q_SLOTS:
ObjSignature * objSignature_;
cv::Mat cameraImage_;
cv::Rect roi_;
KeypointDetector * detector_;
DescriptorExtractor * extractor_;
Feature2D * detector_;
Feature2D * extractor_;

enum State{kTakePicture, kSelectFeatures, kVerifySelection, kClosing};
int state_;
Expand Down
Loading

0 comments on commit 4b5da36

Please sign in to comment.