From fb6afa58a70213326cfe04f1dbad18a450a1f687 Mon Sep 17 00:00:00 2001 From: angelsantamaria <somriu@gmail.com> Date: Mon, 1 May 2017 12:11:31 +0200 Subject: [PATCH] created structure of detector, descriptor and matcher --- .cproject | 59 ++++++++++++++++ .gitignore | 1 + .project | 27 ++++++++ .settings/language.settings.xml | 15 ++++ src/CMakeLists.txt | 18 ++++- src/cam_utils/cam_utils.cpp | 49 +++++++++++++ src/cam_utils/cam_utils.h | 69 +++++++++++++++++++ src/examples/CMakeLists.txt | 7 +- src/examples/capture.cpp | 30 ++++++++ src/examples/feature_detection.cpp | 36 ++++++++++ src/examples/vision_utils_test.cpp | 5 -- src/feature_descriptor/feature_descriptor.cpp | 10 +++ src/feature_descriptor/feature_descriptor.h | 17 +++++ src/feature_detector/feature_detector.cpp | 10 +++ src/feature_detector/feature_detector.h | 17 +++++ src/feature_matcher/feature_matcher.cpp | 10 +++ src/feature_matcher/feature_matcher.h | 17 +++++ 17 files changed, 387 insertions(+), 10 deletions(-) create mode 100644 .cproject create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/language.settings.xml create mode 100644 src/cam_utils/cam_utils.cpp create mode 100644 src/cam_utils/cam_utils.h create mode 100644 src/examples/capture.cpp create mode 100644 src/examples/feature_detection.cpp delete mode 100644 src/examples/vision_utils_test.cpp create mode 100644 src/feature_descriptor/feature_descriptor.cpp create mode 100644 src/feature_descriptor/feature_descriptor.h create mode 100644 src/feature_detector/feature_detector.cpp create mode 100644 src/feature_detector/feature_detector.h create mode 100644 src/feature_matcher/feature_matcher.cpp create mode 100644 src/feature_matcher/feature_matcher.h diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..5ec25d8 --- /dev/null +++ b/.cproject @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1819918851"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1819918851" moduleId="org.eclipse.cdt.core.settings" name="Default"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1819918851" name="Default" parent="org.eclipse.cdt.build.core.emptycfg"> + <folderInfo id="cdt.managedbuild.toolchain.gnu.base.1819918851.1318867162" name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.base.1801134637" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base"> + <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.479045570" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/> + <builder arguments="-j4" buildPath="${workspace_loc:/vision_utils/build}" command="make" id="cdt.managedbuild.target.gnu.builder.base.1436699615" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.401435208" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1649772065" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.146329834" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.593702953" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.392834553" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1306470347" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.537733253" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1810403800" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.base.1501387796" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1737692358" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="vision_utils.null.883408120" name="vision_utils"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> + <storageModule moduleId="refreshScope" versionNumber="2"> + <configuration configurationName="Default"> + <resource resourceType="PROJECT" workspacePath="/vision_utils"/> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> +</cproject> diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e63ddd8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/Default/ diff --git a/.project b/.project new file mode 100644 index 0000000..d2e303f --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>vision_utils</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.eclipse.cdt.core.ccnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + </natures> +</projectDescription> diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml new file mode 100644 index 0000000..22477b0 --- /dev/null +++ b/.settings/language.settings.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<project> + <configuration id="cdt.managedbuild.toolchain.gnu.base.1819918851" name="Default"> + <extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> + <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> + <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> + <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1476617952823822664" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> + <language-scope id="org.eclipse.cdt.core.gcc"/> + <language-scope id="org.eclipse.cdt.core.g++"/> + </provider> + <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> + </extension> + </configuration> +</project> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f85a141..d5f0287 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,17 +1,29 @@ # library source files -SET(sources vision_utils.cpp) +SET(sources vision_utils.cpp cam_utils/cam_utils.cpp feature_detector/feature_detector.cpp feature_descriptor/feature_descriptor.cpp feature_matcher/feature_matcher.cpp) + # application header files -SET(headers vision_utils.h) +SET(headers vision_utils.h cam_utils/cam_utils.h feature_detector/feature_detector.h feature_descriptor/feature_descriptor.h feature_matcher/feature_matcher.h) + # locate the necessary dependencies +FIND_PACKAGE(Eigen3 REQUIRED) +FIND_PACKAGE(OpenCV REQUIRED) + # add the necessary include directories -INCLUDE_DIRECTORIES(.) +INCLUDE_DIRECTORIES(. ${EIGEN3_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS}) + # create the shared library ADD_LIBRARY(vision_utils SHARED ${sources}) + # link necessary libraries +TARGET_LINK_LIBRARIES(vision_utils ${OpenCV_LIBS}) + +# install INSTALL(TARGETS vision_utils RUNTIME DESTINATION bin LIBRARY DESTINATION lib/vision_utils ARCHIVE DESTINATION lib/vision_utils) INSTALL(FILES ${headers} DESTINATION include/vision_utils) INSTALL(FILES ../Findvision_utils.cmake DESTINATION ${CMAKE_ROOT}/Modules/) + +# examples of usage ADD_SUBDIRECTORY(examples) diff --git a/src/cam_utils/cam_utils.cpp b/src/cam_utils/cam_utils.cpp new file mode 100644 index 0000000..d57f926 --- /dev/null +++ b/src/cam_utils/cam_utils.cpp @@ -0,0 +1,49 @@ +#include "cam_utils.h" + +CCamUtils::CCamUtils() +{ +} + +CCamUtils::~CCamUtils() +{ +} + +bool CCamUtils::openCamera(const int& _cam_num, cv::VideoCapture& _cam) +{ + cv::VideoCapture camera(_cam_num); + if (!camera.isOpened()) // check if we succeeded + { + std::cerr << "ERROR: Could not open camera: " << _cam_num << std::endl; + return false; + } + _cam = camera; + return true; +} + +bool CCamUtils::getFrame(cv::VideoCapture& _cam, cv::Mat& _frame) +{ + try + { + _cam >> _frame; + } + catch (cv::Exception& e) + { + std::cout << "An exception occurred. Ignoring frame. " << e.err << std::endl; + return false; + } + return true; +} + +bool CCamUtils::showFrame(const std::string& _window_name, const cv::Mat& _frame) +{ + try + { + cv::imshow(_window_name, _frame); + } + catch (cv::Exception& e) + { + std::cout << "An exception occurred. Ignoring frame. " << e.err << std::endl; + return false; + } + return true; +} diff --git a/src/cam_utils/cam_utils.h b/src/cam_utils/cam_utils.h new file mode 100644 index 0000000..5c06fd4 --- /dev/null +++ b/src/cam_utils/cam_utils.h @@ -0,0 +1,69 @@ +#ifndef _CAMUTILS_H +#define _CAMUTILS_H + +// std stuff +#include <stdio.h> +#include <iostream> + +// OpenCV stuff +#include "opencv2/opencv.hpp" + +class CCamUtils +{ + public: + + /** + * \brief Constructor + * + * Main class constructor. + */ + CCamUtils(); + + /** + * \brief Destructor + * + * Main class destructor. + */ + ~CCamUtils(); + + /** + * \brief Open Webcam + * + * This method opens the specified webcam using OpenCV + * Inputs: + * _cam_num: system camera number (int) + * Ouptuts: + * cam: camera handle (cv::VideoCapture) + * + * Returns true if the camera is correctly opened + * + */ + bool openCamera(const int& _cam_num, cv::VideoCapture& _cam); + + /** + * \brief Get frame + * + * This method gets a frame from the specified webcam + * + * Inputs: + * cam: camera handle (cv::VideoCapture) + * Outputs: + * frame: filled frame (cv::Mat) + * Returns true if the frame is correctly obtained + */ + bool getFrame(cv::VideoCapture& _cam, cv::Mat& _frame); + + /** + *\brief Show Frame + * + * This method shows the specified frame using OpenCV + * + * Inputs: + * window_name: Window name inwhich the frame will be displayed (string) + * frame: Frame to be displayed (cv::Mat) + * Returns true if the frame is correctly displayed + */ + bool showFrame(const std::string& _window_name, const cv::Mat& _frame); +}; + +#endif diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 8615070..c5993b2 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -1,4 +1,7 @@ # create an example application -ADD_EXECUTABLE(vision_utils_test vision_utils_test.cpp) +ADD_EXECUTABLE(capture capture.cpp) +ADD_EXECUTABLE(feature_detection feature_detection.cpp) + # link necessary libraries -TARGET_LINK_LIBRARIES(vision_utils_test vision_utils) +TARGET_LINK_LIBRARIES(capture vision_utils) +TARGET_LINK_LIBRARIES(feature_detection vision_utils) \ No newline at end of file diff --git a/src/examples/capture.cpp b/src/examples/capture.cpp new file mode 100644 index 0000000..a35f5d7 --- /dev/null +++ b/src/examples/capture.cpp @@ -0,0 +1,30 @@ +// OWN stuff +#include "cam_utils/cam_utils.h" +#include "vision_utils.h" + +// STD stuff +#include <string> + +int main(int argc, char *argv[]) +{ + // Camera object definition + cv::VideoCapture cam; + CCamUtils cam_fc; + + // Open camera + cam_fc.openCamera(0, cam); + + for (int nframe = 0; nframe < 1000; ++nframe) + { + // Get frame + cv::Mat frame; + cam_fc.getFrame(cam, frame); + + // Show frame + cv::namedWindow("Cam Test"); + cam_fc.showFrame("Cam Test", frame); + + if (cv::waitKey(30) >= 0) + break; + } +} diff --git a/src/examples/feature_detection.cpp b/src/examples/feature_detection.cpp new file mode 100644 index 0000000..5d510ee --- /dev/null +++ b/src/examples/feature_detection.cpp @@ -0,0 +1,36 @@ +// OWN stuff +#include "cam_utils/cam_utils.h" +#include "vision_utils.h" + +// STD stuff +#include <string> + +int main(int argc, char *argv[]) +{ + // Camera object definition + cv::VideoCapture cam; + CCamUtils cam_fc; + + // Open camera + cam_fc.openCamera(0, cam); + + for (int nframe = 0; nframe < 1000; ++nframe) + { + // Get frame + cv::Mat frame; + cam_fc.getFrame(cam, frame); + + // Show ORIGINAL frame + cv::namedWindow("Cam Test"); + cam_fc.showFrame("Cam Test", frame); + + // Detect features + + + // Show frame with features + + + if (cv::waitKey(30) >= 0) + break; + } +} diff --git a/src/examples/vision_utils_test.cpp b/src/examples/vision_utils_test.cpp deleted file mode 100644 index 5fd6972..0000000 --- a/src/examples/vision_utils_test.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "vision_utils.h" - -int main(int argc, char *argv[]) -{ -} diff --git a/src/feature_descriptor/feature_descriptor.cpp b/src/feature_descriptor/feature_descriptor.cpp new file mode 100644 index 0000000..2b092f9 --- /dev/null +++ b/src/feature_descriptor/feature_descriptor.cpp @@ -0,0 +1,10 @@ +#include "feature_descriptor.h" + +CFeature_Descriptor::CFeature_Descriptor() +{ +} + +CFeature_Descriptor::~CFeature_Descriptor() +{ +} + diff --git a/src/feature_descriptor/feature_descriptor.h b/src/feature_descriptor/feature_descriptor.h new file mode 100644 index 0000000..ecfaea3 --- /dev/null +++ b/src/feature_descriptor/feature_descriptor.h @@ -0,0 +1,17 @@ +#ifndef _FEATURE_DESCRIPTOR_H +#define _FEATURE_DESCRIPTOR_H + +// Descriptor types +enum DESCRIPTOR_TYPE +{ + ORB, SIFT, SURF, AKAZE, KAZE, BRISK, LATCH, FREAK, BRIEF, DAISY, LBD, ROOTSIFT +}; + +class CFeature_Descriptor +{ + public: + CFeature_Descriptor(); + ~CFeature_Descriptor(); +}; + +#endif diff --git a/src/feature_detector/feature_detector.cpp b/src/feature_detector/feature_detector.cpp new file mode 100644 index 0000000..4d8ed66 --- /dev/null +++ b/src/feature_detector/feature_detector.cpp @@ -0,0 +1,10 @@ +#include "feature_detector.h" + +CFeature_Detector::CFeature_Detector() +{ +} + +CFeature_Detector::~CFeature_Detector() +{ +} + diff --git a/src/feature_detector/feature_detector.h b/src/feature_detector/feature_detector.h new file mode 100644 index 0000000..01c2c39 --- /dev/null +++ b/src/feature_detector/feature_detector.h @@ -0,0 +1,17 @@ +#ifndef _FEATURE_DETECTOR_H +#define _FEATURE_DETECTOR_H + +// Descriptor types +enum DETECTOR_TYPE +{ + ORB, SIFT, SURF, AKAZE, KAZE, BRISK, MSER, FAST, LSD, ED, AGAST +}; + +class CFeature_Detector +{ + public: + CFeature_Detector(); + ~CFeature_Detector(); +}; + +#endif diff --git a/src/feature_matcher/feature_matcher.cpp b/src/feature_matcher/feature_matcher.cpp new file mode 100644 index 0000000..d4d34fb --- /dev/null +++ b/src/feature_matcher/feature_matcher.cpp @@ -0,0 +1,10 @@ +#include "feature_matcher.h" + +CFeature_Matcher::CFeature_Matcher() +{ +} + +CFeature_Matcher::~CFeature_Matcher() +{ +} + diff --git a/src/feature_matcher/feature_matcher.h b/src/feature_matcher/feature_matcher.h new file mode 100644 index 0000000..a8eecc2 --- /dev/null +++ b/src/feature_matcher/feature_matcher.h @@ -0,0 +1,17 @@ +#ifndef _FEATURE_MATCHER_H +#define _FEATURE_MATCHER_H + +// Matcher types +enum MATCHER_TYPE +{ + BF_NORM_L2, BF_NORM_HAMMING, BF_NORM_HAMMING2 +}; + +class CFeature_Matcher +{ + public: + CFeature_Matcher(); + ~CFeature_Matcher(); +}; + +#endif -- GitLab