From a07227bf1f2c80cf91bd7e41977fcd64db38bed2 Mon Sep 17 00:00:00 2001 From: Jitesh Pabla Date: Wed, 27 Sep 2017 17:58:29 +0530 Subject: [PATCH 1/5] applied standard comment style and standard cpp bracket layout --- common/utils/ODFeatureDetector2D.cpp | 131 ++++++++++++++++----------- 1 file changed, 77 insertions(+), 54 deletions(-) diff --git a/common/utils/ODFeatureDetector2D.cpp b/common/utils/ODFeatureDetector2D.cpp index 33ed6df1..5f461336 100644 --- a/common/utils/ODFeatureDetector2D.cpp +++ b/common/utils/ODFeatureDetector2D.cpp @@ -6,44 +6,52 @@ #include "ODFeatureDetector2D.h" using namespace std; + namespace od { ODFeatureDetector2D::ODFeatureDetector2D(string type, bool use_gpu) { - mode_ = SIFT; //by default it is SIFT - - if(use_gpu) { + mode_ = SIFT; //by default we set the mode to SIFT + if(use_gpu) + { //##########GPU VERSION - - if(type == "ORB") { + if(type == "ORB") + { mode_ = ORB_GPU; feature_detector_ = cv::cuda::ORB::create(); - } else if(type == "SIFT") { + } + else if(type == "SIFT") + { mode_ = SIFT_GPU; sift_gpu_ = new SiftGPU; - //char * argv[] = {(char *)"-fo", (char *)"-1", (char *)"-v", (char *)"1", (char *)"-cuda", (char *)"0"}; char *argv[] = {(char *) "-fo", (char *) "-1", (char *) "-v", (char *) "1"}; int argc = sizeof(argv) / sizeof(char *); sift_gpu_->ParseParam(argc, argv); if(sift_gpu_->CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED) cout << "FATAL ERROR cannot create SIFTGPU context"; } - } else { + } + else + { //########CPU VERSIONS - - if(type == "SIFT") { + if(type == "SIFT") + { mode_ = SIFT; feature_detector_ = cv::xfeatures2d::SIFT::create(); - } else if(type == "ORB") { + } + else if(type == "ORB") + { mode_ = ORB; feature_detector_ = cv::ORB::create(); - } else if(type == "SURF") { + } + else if(type == "SURF") + { mode_ = SURF; feature_detector_ = cv::xfeatures2d::SURF::create(); } @@ -58,7 +66,6 @@ namespace od feature_detector_->detect(image, keypoints); feature_detector_->compute(image, keypoints, descriptors); } - //viewImage(image, keypoints); } void CVMatToSiftGPU(const cv::Mat &image, unsigned char *siftImage, cv::Mat &grey) @@ -69,15 +76,6 @@ namespace od memcpy(siftImage, grey.data, image.rows * image.cols); - -// tmp2.convertTo(tmp, CV_8U); -// //viewImage(tmp); -// -// for (int y = 0; y < tmp.rows; ++y) { -// for (int x = 0; x < tmp.cols; ++x) { -// siftImage[y * tmp.cols + x] = tmp.at (y, x); -// } -// } return; } @@ -85,63 +83,79 @@ namespace od { unsigned char *data = image.data; cv::Mat greyimage; - if(image.type() != CV_8U) { + if(image.type() != CV_8U) + { cv::cvtColor(image, greyimage, cv::COLOR_BGR2GRAY); data = greyimage.data; } sift_gpu_->RunSIFT(image.cols, image.rows, data, GL_LUMINANCE, GL_UNSIGNED_BYTE); - int nFeat = sift_gpu_->GetFeatureNum();//get feature count - //allocate memory for readback + /** get feature count + */ + int nFeat = sift_gpu_->GetFeatureNum(); + + /** allocate memory for readback + */ vector keys(nFeat); - //read back keypoints and normalized descritpros - //specify NULL if you don’t need keypoints or descriptors + + /** read back keypoints and normalized descritpros + * specify NULL if you don’t need keypoints or descriptors + */ vector imageDescriptors(128 * nFeat); + sift_gpu_->GetFeatureVector(&keys[0], &imageDescriptors[0]); sift_gpu_->SaveSIFT("2.sift"); - //to opencv format + /** to opencv format + */ keypoints.clear(); descriptors.create(0, 128, CV_32FC1); - for(int i = 0; i < nFeat; ++i) { + + for(int i = 0; i < nFeat; ++i) + { cv::KeyPoint key(keys[i].x, keys[i].y, keys[i].s, keys[i].o); keypoints.push_back(key); cv::Mat descriptor(1, 128, CV_32FC1); - for(int x = 0; x < 128; x++) - descriptor.at(x) = floor(0.5 + (512.0f * imageDescriptors[(i * 128) + x])); + for(int j = 0; j < 128; j++) + descriptor.at(j) = floor(0.5 + (512.0f * imageDescriptors[(i * 128) + j])); descriptors.push_back(descriptor); } - - //viewImage(image, keypoints); - } void ODFeatureDetector2D::findSiftGPUDescriptors(cv::Mat const &image, cv::Mat &descriptors, vector &keypoints) { unsigned char *data = image.data; cv::Mat greyimage; - if(image.type() != CV_8U) { - cv::Mat tmp; - cv::cvtColor(image, tmp, cv::COLOR_BGR2GRAY); - data = tmp.data; + if(image.type() != CV_8U) + { + cv::cvtColor(image, greyimage, cv::COLOR_BGR2GRAY); + data = greyimage.data; } sift_gpu_->RunSIFT(image.cols, image.rows, data, GL_LUMINANCE, GL_UNSIGNED_BYTE); - int nFeat = sift_gpu_->GetFeatureNum();//get feature count - //allocate memory for readback + /** get feature count + */ + int nFeat = sift_gpu_->GetFeatureNum(); + + /** allocate memory for readback + */ vector keys(nFeat); - //read back keypoints and normalized descritpros - //specify NULL if you don’t need keypoints or descriptors + + /** read back keypoints and normalized descritpros + * specify NULL if you don’t need keypoints or descriptors + */ vector imageDescriptors(128 * nFeat); + sift_gpu_->GetFeatureVector(&keys[0], &imageDescriptors[0]); sift_gpu_->SaveSIFT("2.sift"); - //to opencv format + /** to opencv format + */ keypoints.clear(); cv::Mat descriptormat = cv::Mat(1, nFeat, CV_32F, &imageDescriptors[0]); descriptormat.copyTo(descriptors); @@ -151,29 +165,35 @@ namespace od keypoints.push_back(key); } - - //viewImage(image, keypoints); - } void ODFeatureDetector2D::findSiftGPUDescriptors(char const *image_name, cv::Mat &descriptors, vector &keypoints) { sift_gpu_->RunSIFT(image_name); - int nFeat = sift_gpu_->GetFeatureNum();//get feature count - //allocate memory for readback + /** get feature count + */ + int nFeat = sift_gpu_->GetFeatureNum(); + + /** allocate memory for readback + */ vector keys(nFeat); - //read back keypoints and normalized descritpros - //specify NULL if you don’t need keypoints or descriptors + + /** read back keypoints and normalized descritpros + * specify NULL if you don’t need keypoints or descriptors + */ vector imageDescriptors(128 * nFeat); + sift_gpu_->GetFeatureVector(&keys[0], &imageDescriptors[0]); sift_gpu_->SaveSIFT("1.sift"); - //to opencv format + /** to opencv format + */ keypoints.clear(); descriptors.create(0, 128, CV_32FC1); - for(int i = 0; i < nFeat; ++i) { + for(int i = 0; i < nFeat; ++i) + { cv::KeyPoint key(keys[i].x, keys[i].y, keys[i].s, keys[i].o); keypoints.push_back(key); cv::Mat descriptor(1, 128, CV_32FC1); @@ -187,10 +207,13 @@ namespace od { cv::Mat descriptors; vector keypoints; - if(mode_ == SIFT_GPU) { + if(mode_ == SIFT_GPU) + { findSiftGPUDescriptors1(image, descriptors, keypoints); sift_gpu_->SaveSIFT(path.c_str()); - } else { + } + else + { //DO NOTHING! IMPLEMENT LATER } From 577bc633aa968c8b827dbff3fe9e311d4825ce5c Mon Sep 17 00:00:00 2001 From: Jitesh Pabla Date: Wed, 27 Sep 2017 18:18:33 +0530 Subject: [PATCH 2/5] applied standard curly bracket layout. Removed unnecessary commented code --- common/utils/ODFeatureDetector2D.h | 42 +++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/common/utils/ODFeatureDetector2D.h b/common/utils/ODFeatureDetector2D.h index 24535a47..9f4a4d26 100644 --- a/common/utils/ODFeatureDetector2D.h +++ b/common/utils/ODFeatureDetector2D.h @@ -36,23 +36,51 @@ namespace od mode_ = type; - if(type == SIFT) { + switch(type) + { + case SIFT: + feature_detector_ = cv::xfeatures2d::SIFT::create(); + case ORB: + feature_detector_ = cv::ORB::create(); + case SURF: + feature_detector_ = cv::xfeatures2d::SURF::create(); + case ORB_GPU: + feature_detector_ = cv::cuda::ORB::create(); + case SIFT_GPU: + sift_gpu_ = new SiftGPU; + char *argv[] = {(char *) "-fo", (char *) "-1", (char *) "-v", (char *) "3", (char *) "-cuda"}; + int argc = sizeof(argv) / sizeof(char *); + sift_gpu_->ParseParam(argc, argv); + if(sift_gpu_->CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED) + std::cout << "FATAL ERROR cannot create SIFTGPU context"; + } + + /* + if(type == SIFT) + { feature_detector_ = cv::xfeatures2d::SIFT::create(); - } else if(type == ORB) { + } + else if(type == ORB) + { feature_detector_ = cv::ORB::create(); - } else if(type == SURF) { + } + else if(type == SURF) + { feature_detector_ = cv::xfeatures2d::SURF::create(); - } else if(type == ORB_GPU) { + } + else if(type == ORB_GPU) + { feature_detector_ = cv::cuda::ORB::create(); - } else if(type == SIFT_GPU) { + } + else if(type == SIFT_GPU) + { sift_gpu_ = new SiftGPU; - //char * argv[] = {(char *)"-fo", (char *)"-1", (char *)"-v", (char *)"1"}; char *argv[] = {(char *) "-fo", (char *) "-1", (char *) "-v", (char *) "3", (char *) "-cuda"}; int argc = sizeof(argv) / sizeof(char *); sift_gpu_->ParseParam(argc, argv); if(sift_gpu_->CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED) std::cout << "FATAL ERROR cannot create SIFTGPU context"; - } + }*/ } //always return Opencv type keypoints From 9b2cd638947a13e867398c988973a9d9fd7b89b7 Mon Sep 17 00:00:00 2001 From: Jitesh Pabla Date: Wed, 27 Sep 2017 18:20:56 +0530 Subject: [PATCH 3/5] Replaced if else staements with switch case. Applied standard curly bracket layout. Removed unnecessary commented code. --- common/utils/ODFrameGenerator.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/common/utils/ODFrameGenerator.h b/common/utils/ODFrameGenerator.h index fd675b77..c3fa9c28 100644 --- a/common/utils/ODFrameGenerator.h +++ b/common/utils/ODFrameGenerator.h @@ -18,8 +18,6 @@ namespace od GENERATOR_TYPE_FILE_LIST, GENERATOR_TYPE_DEVICE }; - - /** \brief The FrameGenerator class for capturing and reading Scenes conveniently. * Templated with two parameters - SceneType identifying a Scene class, and TYPE identifying the type of input. After the instantiation with a correct TYPE, use the function * getNextFrame() to get an instance of next scene of SceneType. getNextFrame() returns valid scenes until all scenes matched are exhausted - the time when 'isValid()' is false. @@ -27,9 +25,11 @@ namespace od * \tparam SceneT One of the Scene classes - ODSceneImage or ODScenePointCloud * \tparam TYPE TYPE can be GENERATOR_TYPE_FILE_LIST which means you provide the list of scene files to be returned by the FrameGenerator in the constructor (for eg. \/home/username/pics/*.jpg) * Or it can be GENERATOR_TYPE_DEVICE which picks up the webcam or the kinect based on the SceneType. - * \author Kripasindhu Sarkar - * - */ + * + * \author Kripasindhu Sarkar + * + */ + template class ODFrameGenerator { @@ -146,7 +146,6 @@ namespace od }; */ - template<> class ODFrameGenerator , GENERATOR_TYPE_DEVICE> { @@ -156,7 +155,8 @@ namespace od typedef pcl::PointCloud::Ptr PointCloudPtr; typedef pcl::PointCloud::ConstPtr PointCloudConstPtr; - /* A simple class for capturing data from an OpenNI camera */ + /** A simple class for capturing data from an OpenNI camera + */ ODFrameGenerator(std::string input = "") : grabber_(input), most_recent_frame_(), frame_counter_(0), active_(true) { boost::function frame_cb = boost::bind (&ODFrameGenerator , GENERATOR_TYPE_DEVICE>::onNewFrame, this, _1); @@ -167,7 +167,8 @@ namespace od ~ODFrameGenerator() { - // Stop the grabber when shutting down + /**Stop the grabber when shutting down + */ grabber_.stop (); } @@ -191,7 +192,8 @@ namespace od } void onKeyboardEvent (const pcl::visualization::KeyboardEvent & event) { - // When the spacebar is pressed, trigger a frame capture + /**When the spacebar is pressed, trigger a frame capture + */ mutex_.lock (); if (event.keyDown () && event.getKeySym () == "e") { From 3e8f8d9a61be50293cb28a20c55521ad35caa836 Mon Sep 17 00:00:00 2001 From: Jitesh Pabla Date: Thu, 28 Sep 2017 01:30:11 +0530 Subject: [PATCH 4/5] Update installation_instruction.rst Added additional instructions for missing dependencies and possible errors. --- .../content/installation_instruction.rst | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/doc/tutorials/content/installation_instruction.rst b/doc/tutorials/content/installation_instruction.rst index 7209570b..0d06b167 100644 --- a/doc/tutorials/content/installation_instruction.rst +++ b/doc/tutorials/content/installation_instruction.rst @@ -9,7 +9,7 @@ To compile OD from source, install its dependencies as stated below. Dependencies ------------ -1. OpenCV 3.0 +1. OpenCV 3.0 or above :Source: http://opencv.org/downloads.html or https://github.com/Itseez/opencv @@ -19,19 +19,33 @@ Dependencies - OpenCV contrib (for xfeatures2d module handing SIFT/SURF features): Detailed instructions with source: https://github.com/itseez/opencv_contrib + (make sure to get the same version of OpenCV and OpenCV contrib) :Additional CMAKE options: OPENCV_EXTRA_MODULES_PATH=/modules - OpenCV CUDA module (for GPU enabled feature detectors and matcher): + CUDA Downloads: https://developer.nvidia.com/cuda-downloads + Detailed installation instructions: http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html + :Additional CMAKE options: WITH_CUDA=ON + + - VTK 5.x.x or 6.x.x + + VTK Downloads: https://www.vtk.org/download/ + Detailed installation instructions: https://www.vtk.org/Wiki/VTK/Configure_and_Build + (No need to build VTK with QT) + + :Additional CMAKE options: WITH_VTK=ON + Compile and install Opencv 3.0 with the above settings. -2. VTK 6.0 or above +2. VTK 7.0 or above Just download and compile latest VTK with its default settings. + (Don't worry about having 2 different VTK versions on your system) 3. PCL 1.6 or above @@ -46,7 +60,39 @@ Dependencies 4. Eigen -OD + Get the latest version of Eigen (source) using your package manager. + +5. SVMLight + + We use SVMLight for training. To user the feature of training using SVMLight, you need to download the source and put in a specific folder (we could not include the source in 3rdparty because of its restrictive licence). Please see http://svmlight.joachims.org/ for the details and terms of use. + + Download the source code from http://svmlight.joachims.org/ and extract it to opendetection/3rdparty/svmlight. You should have files like svm_common.c, svm_learn.c, etc. under the directory opendetection/3rdparty/svmlight. + +6. Additional dependencies + + These may or may not be present on your system already: + + - FreeGlut (package name - freeglut3-dev) + - libusb (package name - lib-1.0.0-dev) + - Flann (package name - libflann-dev) + - GLEW (package name - libglew-dev) + +Installing Open Detection -- -Download the source from https://github.com/krips89/opendetection. With the above dependencies installed, OD should compile fine. If you still encounter a problem shoot an email at krips.from.iit.kgp@gmail.com. +Download the source from https://github.com/krips89/opendetection. With the above dependencies installed, OD should compile fine. The code while platform independent, is only tested and run in Linux machine. Instructions for the usage for linux are provided below: + +Compile out of source using cmake+your favorite compiler. For example: + +Download the code:: + + cd + git clone https://github.com/krips89/opendetection.git + +configure with CMake and compile:: + + cd + mkdir build; cd build + cmake .. + make + make install From 9c3588d40972386519bdc29bc56ac64e8d5c4e32 Mon Sep 17 00:00:00 2001 From: Jitesh Pabla Date: Thu, 28 Sep 2017 01:31:40 +0530 Subject: [PATCH 5/5] Updated heading formatting --- doc/tutorials/content/installation_instruction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorials/content/installation_instruction.rst b/doc/tutorials/content/installation_instruction.rst index 0d06b167..b6d03e40 100644 --- a/doc/tutorials/content/installation_instruction.rst +++ b/doc/tutorials/content/installation_instruction.rst @@ -78,7 +78,7 @@ Dependencies - GLEW (package name - libglew-dev) Installing Open Detection --- +------------------------- Download the source from https://github.com/krips89/opendetection. With the above dependencies installed, OD should compile fine. The code while platform independent, is only tested and run in Linux machine. Instructions for the usage for linux are provided below: Compile out of source using cmake+your favorite compiler. For example: