Skip to content
Snippets Groups Projects
Commit 0b1471db authored by angelsantamaria's avatar angelsantamaria
Browse files

detection with brute force done.

parent 6887c2dd
No related branches found
No related tags found
No related merge requests found
...@@ -6,24 +6,25 @@ ...@@ -6,24 +6,25 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// Camera object definition // Open camera
cv::VideoCapture cam; cv::VideoCapture cam;
CCamUtils cam_fc; CCamUtils cam_fc;
// Open camera
cam_fc.openCamera(0, cam); cam_fc.openCamera(0, cam);
for (int nframe = 0; nframe < 1000; ++nframe) cv::startWindowThread();
cv::namedWindow("Cam Test", 1);
for (;;)
{ {
// Get frame // Get frame
cv::Mat frame; cv::Mat frame;
cam_fc.getFrame(cam, frame); cam_fc.getFrame(cam, frame);
// Show frame // Show frame
cv::namedWindow("Cam Test"); cv::imshow("Cam Test", frame);
cam_fc.showFrame("Cam Test", frame); cv::waitKey(1);
//if (cv::waitKey(30) >= 0) break;
if (cv::waitKey(30) >= 0)
break;
} }
cv::destroyAllWindows();
} }
...@@ -6,13 +6,46 @@ ...@@ -6,13 +6,46 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// Camera object definition std::cout << "----------------------------------------" << std::endl;
cv::VideoCapture cam; std::cout << "| Feature detector example |" << std::endl;
CCamUtils cam_fc; std::cout << "----------------------------------------" << std::endl;
std::cout << std::endl;
std::vector<std::string> options;
options.resize(11);
options[0] = "ORB";
options[1] = "SIFT";
options[2] = "SURF";
options[3] = "AKAZE";
options[4] = "KAZE";
options[5] = "BRISK";
options[6] = "MSER";
options[7] = "FAST";
options[8] = "LSD";
options[9] = "ED";
options[10] = "AGAST";
for (unsigned int ii=0; ii<options.size(); ii++)
std::cout << "[" << ii << "]: " << options[ii] << std::endl;
std::cout << std::endl << "Which feature do you want to test?: ";
int feat_type;
std::cin >> feat_type;
std::cout << std::endl << "Testing: " << options[feat_type] << std::endl;
// Open camera // Open camera
cv::VideoCapture cam;
CCamUtils cam_fc;
cam_fc.openCamera(0, cam); cam_fc.openCamera(0, cam);
// Create displays
cv::startWindowThread();
cv::namedWindow("Original image", cv::WINDOW_NORMAL);
cv::namedWindow("Detections", cv::WINDOW_NORMAL);
// The following line is used to remove the OpenCV "init done" from the terminal
std::cout << "\e[A" << " " << std::endl;
for (int nframe = 0; nframe < 1000; ++nframe) for (int nframe = 0; nframe < 1000; ++nframe)
{ {
// Get frame // Get frame
...@@ -20,22 +53,33 @@ int main(int argc, char *argv[]) ...@@ -20,22 +53,33 @@ int main(int argc, char *argv[])
cam_fc.getFrame(cam, frame); cam_fc.getFrame(cam, frame);
// Show ORIGINAL frame // Show ORIGINAL frame
cv::namedWindow("Original image"); cv::imshow("Original image", frame);
cam_fc.showFrame("Original image", frame);
// Detect features (keypoints) // Detect features (keypoints)
CFeature_Detector detector(ORB); CFeature_Detector detector(feat_type);
CFeature_Detector::KeyPointVector keypoints;
keypoints = detector.detectKeyPoints(frame);
// Show frame with features if (feat_type!=8 && feat_type!=9)
detector.drawKeyFeatures(frame, keypoints); {
CFeature_Detector::KeyPointVector keypoints;
keypoints = detector.detectKeyPoints(frame);
// Show frame with features
detector.drawKeyFeatures(frame, keypoints);
}
else
{
CFeature_Detector::KeyLineVector keypoints;
keypoints = detector.detectKeyLines(frame);
// Show frame with features
detector.drawKeyFeatures(frame, keypoints);
}
// Show NEW frame std::cout << "\e[A" << "Detection time: " << detector.getDetectionTime() << std::endl;
cv::namedWindow("Detections");
cam_fc.showFrame("Detections", frame);
if (cv::waitKey(30) >= 0) // Show NEW frame
break; cv::imshow("Detections", frame);
cv::waitKey(1);
// if (cv::waitKey(30) >= 0) break;
} }
cv::destroyAllWindows();
} }
#include "feature_detector.h" #include "feature_detector.h"
CFeature_Detector::CFeature_Detector(DETECTOR_TYPE _type) : CFeature_Detector::CFeature_Detector(const DETECTOR_TYPE& _type) :
is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0) is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0)
{ {
init(_type); is_init_ = init(_type);
if (!is_init_) if (!is_init_)
{ {
...@@ -12,6 +12,19 @@ CFeature_Detector::CFeature_Detector(DETECTOR_TYPE _type) : ...@@ -12,6 +12,19 @@ CFeature_Detector::CFeature_Detector(DETECTOR_TYPE _type) :
} }
} }
CFeature_Detector::CFeature_Detector(const int&_type) :
is_init_(false), is_line_(false), is_limited_(false), keypoints_limit_(-1), detect_time_(0.0)
{
is_init_ = init( intToDetectorType(_type) );
if (!is_init_)
{
std::cerr << "[Feature Detector]: Something went wrong during initialization! Feature Detector not initialized."
<< std::endl;
}
}
CFeature_Detector::~CFeature_Detector() CFeature_Detector::~CFeature_Detector()
{ {
} }
...@@ -82,7 +95,9 @@ CFeature_Detector::KeyPointVector CFeature_Detector::detectKeyPoints(const cv::M ...@@ -82,7 +95,9 @@ CFeature_Detector::KeyPointVector CFeature_Detector::detectKeyPoints(const cv::M
{ {
KeyPointVector kpts; KeyPointVector kpts;
clock_t tStart = clock();
feature_detector_->detect(_image, kpts); feature_detector_->detect(_image, kpts);
detect_time_ = (double)(clock() - tStart)/CLOCKS_PER_SEC;
if (this->isLimited()) if (this->isLimited())
{ {
...@@ -98,10 +113,12 @@ CFeature_Detector::KeyLineVector CFeature_Detector::detectKeyLines(const cv::Mat ...@@ -98,10 +113,12 @@ CFeature_Detector::KeyLineVector CFeature_Detector::detectKeyLines(const cv::Mat
KeyLineVector kls; KeyLineVector kls;
KeyLineVector kls2; KeyLineVector kls2;
clock_t tStart = clock();
if (type_ == LSD) if (type_ == LSD)
lsd_detector_->detect(_image, kls, SCALE_FACTOR_LINE_DETECTOR, NUM_OCTAVE_LINE_DETECTOR); lsd_detector_->detect(_image, kls, SCALE_FACTOR_LINE_DETECTOR, NUM_OCTAVE_LINE_DETECTOR);
else else
ed_detector_->detect(_image, kls2); ed_detector_->detect(_image, kls2);
detect_time_ = (double)(clock() - tStart)/CLOCKS_PER_SEC;
kls.insert(kls.end(), kls2.begin(), kls2.end()); kls.insert(kls.end(), kls2.begin(), kls2.end());
return kls; return kls;
......
#ifndef _FEATURE_DETECTOR_H #ifndef _FEATURE_DETECTOR_H
#define _FEATURE_DETECTOR_H #define _FEATURE_DETECTOR_H
#include <time.h>
// OpenCV stuff // OpenCV stuff
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/core/types.hpp> #include <opencv2/core/types.hpp>
...@@ -20,7 +22,10 @@ typedef cv::Ptr<cv::line_descriptor::BinaryDescriptor> EDDetector; ...@@ -20,7 +22,10 @@ typedef cv::Ptr<cv::line_descriptor::BinaryDescriptor> EDDetector;
/** /**
* brief Descriptor types * brief Descriptor types
*/ */
enum DETECTOR_TYPE { ORB, SIFT, SURF, AKAZE, KAZE, BRISK, MSER, FAST, LSD, ED, AGAST }; enum DETECTOR_TYPE
{
ORB, SIFT, SURF, AKAZE, KAZE, BRISK, MSER, FAST, LSD, ED, AGAST
};
/** /**
* \brief Stream operator for the detector flags. * \brief Stream operator for the detector flags.
...@@ -68,6 +73,42 @@ inline std::ostream& operator<<(std::ostream& _os, DETECTOR_TYPE _f) ...@@ -68,6 +73,42 @@ inline std::ostream& operator<<(std::ostream& _os, DETECTOR_TYPE _f)
return _os; return _os;
} }
/**
* \brief Convert an integer to its corresponding descriptor flag.
*
* By default return L2.
*/
inline DETECTOR_TYPE intToDetectorType(const unsigned int _i)
{
switch (_i)
{
case 0:
return ORB;
case 1:
return SIFT;
case 2:
return SURF;
case 3:
return AKAZE;
case 4:
return KAZE;
case 5:
return BRISK;
case 6:
return MSER;
case 7:
return FAST;
case 8:
return LSD;
case 9:
return ED;
case 10:
return AGAST;
default:
return ORB;
}
}
class CFeature_Detector class CFeature_Detector
{ {
public: public:
...@@ -75,21 +116,38 @@ class CFeature_Detector ...@@ -75,21 +116,38 @@ class CFeature_Detector
typedef std::vector<cv::KeyPoint> KeyPointVector; typedef std::vector<cv::KeyPoint> KeyPointVector;
typedef std::vector<cv::line_descriptor::KeyLine> KeyLineVector; typedef std::vector<cv::line_descriptor::KeyLine> KeyLineVector;
bool getDetectionTime() { return detect_time_; }; CFeature_Detector(const DETECTOR_TYPE& _type);
CFeature_Detector(const int& _type);
~CFeature_Detector();
bool isLine() { return is_line_; }; double getDetectionTime()
bool isLimited() { return is_limited_; }; {
int getKeyPointsLimit() { return keypoints_limit_; }; return detect_time_;
}
;
bool isLine()
{
return is_line_;
}
;
bool isLimited()
{
return is_limited_;
}
;
int getKeyPointsLimit()
{
return keypoints_limit_;
}
;
bool limitKeypts(unsigned int _nFeatures); bool limitKeypts(unsigned int _nFeatures);
CFeature_Detector(DETECTOR_TYPE _type);
~CFeature_Detector();
KeyPointVector detectKeyPoints(const cv::Mat&); KeyPointVector detectKeyPoints(const cv::Mat&);
KeyLineVector detectKeyLines(const cv::Mat&); KeyLineVector detectKeyLines(const cv::Mat&);
cv::Mat drawKeyFeatures( const cv::Mat& _image, const std::vector<cv::KeyPoint>& _kp_vec ); cv::Mat drawKeyFeatures(const cv::Mat& _image, const std::vector<cv::KeyPoint>& _kp_vec);
cv::Mat drawKeyFeatures( const cv::Mat& _image, const std::vector<cv::line_descriptor::KeyLine>& _kl_vec ); cv::Mat drawKeyFeatures(const cv::Mat& _image, const std::vector<cv::line_descriptor::KeyLine>& _kl_vec);
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment