From 68a993a2aa702e7c2224cf0a299aae834896ceca Mon Sep 17 00:00:00 2001 From: vaibhavs825 Date: Wed, 27 Sep 2017 17:47:53 +0530 Subject: [PATCH 1/5] applied standard curly braces layout. --- common/utils/utils.cpp | 75 ++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/common/utils/utils.cpp b/common/utils/utils.cpp index f00f1b68..bcf78755 100644 --- a/common/utils/utils.cpp +++ b/common/utils/utils.cpp @@ -1,6 +1,7 @@ // // Created by sarkar on 19.06.15. // + #include "utils.h" #include "opencv2/imgproc/imgproc.hpp" #include @@ -11,16 +12,14 @@ using namespace cv; namespace od { - std::vector myglob(const std::string &pat) { using namespace std; glob_t glob_result; glob(pat.c_str(), GLOB_TILDE, NULL, &glob_result); vector ret; - for(unsigned int i = 0; i < glob_result.gl_pathc; ++i) { + for(unsigned int i = 0; i < glob_result.gl_pathc; ++i) ret.push_back(string(glob_result.gl_pathv[i])); - } globfree(&glob_result); return ret; } @@ -30,9 +29,11 @@ namespace od for (int r = 0; r < descriptors.rows; r++) { float norm=0; - for (int c = 0; c < descriptors.cols; c++) norm+=(descriptors.at(r, c)*descriptors.at(r, c)); + for (int c = 0; c < descriptors.cols; c++) + norm+=(descriptors.at(r, c)*descriptors.at(r, c)); norm = 1.0/sqrt(norm); - for (int c = 0; c < descriptors.cols; c++) descriptors.at(r, c)*=norm; + for (int c = 0; c < descriptors.cols; c++) + descriptors.at(r, c)*=norm; } } @@ -46,38 +47,49 @@ namespace od int maxRowLength = 0; std::vector resizeWidth; - for (int i = 0; i < N;) { + for (int i = 0; i < N;) + { int thisRowLen = 0; - for (int k = 0; k < imagesPerRow; k++) { + for (int k = 0; k < imagesPerRow; k++) + { double aspectRatio = double(vecMat[i].cols) / vecMat[i].rows; int temp = int( ceil(resizeHeight * aspectRatio)); resizeWidth.push_back(temp); thisRowLen += temp; if (++i == N) break; } - if ((thisRowLen + edgeThickness * (imagesPerRow + 1)) > maxRowLength) { + if ((thisRowLen + edgeThickness * (imagesPerRow + 1)) > maxRowLength) + { maxRowLength = thisRowLen + edgeThickness * (imagesPerRow + 1); } } + int windowWidth = maxRowLength; cv::Mat canvasImage(windowHeight, windowWidth, CV_8UC3, cv::Scalar(0, 0, 0)); - for (int k = 0, i = 0; i < nRows; i++) { + for (int k = 0, i = 0; i < nRows; i++) + { int y = i * resizeHeight + (i + 1) * edgeThickness; int x_end = edgeThickness; - for (int j = 0; j < imagesPerRow && k < N; k++, j++) { + for (int j = 0; j < imagesPerRow && k < N; k++, j++) + { int x = x_end; cv::Rect roi(x, y, resizeWidth[k], resizeHeight); cv::Size s = canvasImage(roi).size(); - // change the number of channels to three + + /**change the number of channels to three + */ cv::Mat target_ROI(s, CV_8UC3); - if (vecMat[k].channels() != canvasImage.channels()) { - if (vecMat[k].channels() == 1) { + if (vecMat[k].channels() != canvasImage.channels()) + { + if (vecMat[k].channels() == 1) + { cv::cvtColor(vecMat[k], target_ROI, CV_GRAY2BGR); } } cv::resize(target_ROI, target_ROI, s); - if (target_ROI.type() != canvasImage.type()) { + if (target_ROI.type() != canvasImage.type()) + { target_ROI.convertTo(target_ROI, canvasImage.type()); } target_ROI.copyTo(canvasImage(roi)); @@ -107,8 +119,11 @@ namespace od if (messages.size() == imgs.size()) printmssg = true; float nImgs=imgs.size(); - int imgsInRow=ceil(sqrt(nImgs)); // You can set this explicitly - int imgsInCol=ceil(nImgs/imgsInRow); // You can set this explicitly + + /** imgsInRow and imgsInCol can be set explicitly. + */ + int imgsInRow=ceil(sqrt(nImgs)); + int imgsInCol=ceil(nImgs/imgsInRow); int resultImgW=cellSize.width*imgsInRow; int resultImgH=cellSize.height*imgsInCol; @@ -157,38 +172,48 @@ namespace od int maxRowLength = 0; std::vector resizeWidth; - for (int i = 0; i < N;) { + for (int i = 0; i < N;) + { int thisRowLen = 0; - for (int k = 0; k < imagesPerRow; k++) { + for (int k = 0; k < imagesPerRow; k++) + { double aspectRatio = double(vecMat[i].cols) / vecMat[i].rows; int temp = int( ceil(resizeHeight * aspectRatio)); resizeWidth.push_back(temp); thisRowLen += temp; if (++i == N) break; } - if ((thisRowLen + edgeThickness * (imagesPerRow + 1)) > maxRowLength) { + if ((thisRowLen + edgeThickness * (imagesPerRow + 1)) > maxRowLength) + { maxRowLength = thisRowLen + edgeThickness * (imagesPerRow + 1); } } int windowWidth = maxRowLength; cv::Mat canvasImage(windowHeight, windowWidth, CV_8UC3, cv::Scalar(0, 0, 0)); - for (int k = 0, i = 0; i < nRows; i++) { + for (int k = 0, i = 0; i < nRows; i++) + { int y = i * resizeHeight + (i + 1) * edgeThickness; int x_end = edgeThickness; - for (int j = 0; j < imagesPerRow && k < N; k++, j++) { + for (int j = 0; j < imagesPerRow && k < N; k++, j++) + { int x = x_end; cv::Rect roi(x, y, resizeWidth[k], resizeHeight); cv::Size s = canvasImage(roi).size(); - // change the number of channels to three + + /**change the number of channels to three + */ cv::Mat target_ROI(s, CV_8UC3); - if (vecMat[k].channels() != canvasImage.channels()) { - if (vecMat[k].channels() == 1) { + if (vecMat[k].channels() != canvasImage.channels()) + { + if (vecMat[k].channels() == 1) + { cv::cvtColor(vecMat[k], target_ROI, CV_GRAY2BGR); } } cv::resize(target_ROI, target_ROI, s); - if (target_ROI.type() != canvasImage.type()) { + if (target_ROI.type() != canvasImage.type()) + { target_ROI.convertTo(target_ROI, canvasImage.type()); } target_ROI.copyTo(canvasImage(roi)); From 5eaf5d569452f5462f08dc25b23ae1d66e0d678a Mon Sep 17 00:00:00 2001 From: vaibhavs825 Date: Wed, 27 Sep 2017 17:57:34 +0530 Subject: [PATCH 2/5] Removed unnecessary backslash characters and applied standard curly braces layout --- common/utils/utils.h | 160 ++++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 71 deletions(-) diff --git a/common/utils/utils.h b/common/utils/utils.h index 0bee4314..8d7d30f7 100644 --- a/common/utils/utils.h +++ b/common/utils/utils.h @@ -20,35 +20,36 @@ namespace bf = boost::filesystem; -/** \brief misclenious helping functions; will be refactored later +/** \brief miscellaneous helping functions; will be refactored later * * \author Kripasindhu Sarkar * */ - -#define X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE(r, data, elem) \ +#define X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE(r, data, elem) case elem : return BOOST_PP_STRINGIZE(elem); -#define OD_DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators) \ - enum name { \ - BOOST_PP_SEQ_ENUM(enumerators) \ - }; \ - \ - inline const char* enumToString(name v) \ - { \ - switch (v) \ - { \ - BOOST_PP_SEQ_FOR_EACH( \ - X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, \ - name, \ - enumerators \ - ) \ - default: return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; \ - } \ +#define OD_DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators) + enum name + { + BOOST_PP_SEQ_ENUM(enumerators) + }; + + inline const char* enumToString(name v) + { + switch (v) + { + BOOST_PP_SEQ_FOR_EACH( + X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, + name, + enumerators + ) + default: return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; + } } + namespace od { @@ -151,7 +152,9 @@ namespace od double getDuration() - { return duration_; } + { + return duration_; + } static void printTime(double duration) { @@ -223,43 +226,50 @@ namespace od static void getFilesInDirectoryInternal(bf::path &dir, std::string &rel_path_so_far, std::vector &relative_paths, std::vector exts) { bf::directory_iterator end_itr; - for(bf::directory_iterator itr(dir); itr != end_itr; ++itr) { - //check if its a directory, then get models in it - if(bf::is_directory(*itr)) { -#if BOOST_FILESYSTEM_VERSION == 3 - std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/"; -#else + for(bf::directory_iterator itr(dir); itr != end_itr; ++itr) + { + + /** check if its a directory, then get models in it + */ + if(bf::is_directory(*itr)) + { + #if BOOST_FILESYSTEM_VERSION == 3 + std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/"; + #else std::string so_far = rel_path_so_far + (itr->path ()).filename () + "/"; -#endif + #endif bf::path curr_path = itr->path(); getFilesInDirectoryInternal(curr_path, so_far, relative_paths, exts); - } else { - //check that it is a ply file and then add, otherwise ignore.. + } + else + { + /**check that it is a ply file and then add, otherwise ignore. + */ std::vector strs; -#if BOOST_FILESYSTEM_VERSION == 3 - std::string file = (itr->path().filename()).string(); -#else + #if BOOST_FILESYSTEM_VERSION == 3 + std::string file = (itr->path().filename()).string(); + #else std::string file = (itr->path ()).filename (); -#endif + #endif boost::split(strs, file, boost::is_any_of(".")); std::string extension = strs[strs.size() - 1]; bool flagfound = false; for (int exti = 0; exti < exts.size(); exti ++) - if(file.rfind(exts[exti]) != std::string::npos) - { flagfound = true; break; } + if(file.rfind(exts[exti]) != std::string::npos) + { flagfound = true; break; } if( flagfound == true ) { -#if BOOST_FILESYSTEM_VERSION == 3 - std::string path = rel_path_so_far + (itr->path().filename()).string(); -#else + #if BOOST_FILESYSTEM_VERSION == 3 + std::string path = rel_path_so_far + (itr->path().filename()).string(); + #else std::string path = rel_path_so_far + (itr->path ()).filename (); -#endif - std::string fullpath = rel_path_so_far + itr->path().string(); - relative_paths.push_back(fullpath); + #endif + std::string fullpath = rel_path_so_far + itr->path().string(); + relative_paths.push_back(fullpath); } } } @@ -268,36 +278,40 @@ namespace od static void getFilesInDirectoryInternal(bf::path &dir, std::string &rel_path_so_far, std::vector &relative_paths, std::string const &ext) { bf::directory_iterator end_itr; - for(bf::directory_iterator itr(dir); itr != end_itr; ++itr) { + for(bf::directory_iterator itr(dir); itr != end_itr; ++itr) + { //check if its a directory, then get models in it - if(bf::is_directory(*itr)) { -#if BOOST_FILESYSTEM_VERSION == 3 - std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/"; -#else + if(bf::is_directory(*itr)) + { + #if BOOST_FILESYSTEM_VERSION == 3 + std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/"; + #else std::string so_far = rel_path_so_far + (itr->path ()).filename () + "/"; -#endif + #endif bf::path curr_path = itr->path(); getFilesInDirectoryInternal(curr_path, so_far, relative_paths, ext); - } else { + } + else + { //check that it is a ply file and then add, otherwise ignore.. std::vector strs; -#if BOOST_FILESYSTEM_VERSION == 3 - std::string file = (itr->path().filename()).string(); -#else + #if BOOST_FILESYSTEM_VERSION == 3 + std::string file = (itr->path().filename()).string(); + #else std::string file = (itr->path ()).filename (); -#endif + #endif boost::split(strs, file, boost::is_any_of(".")); std::string extension = strs[strs.size() - 1]; if( file.rfind(ext) != std::string::npos ) { -#if BOOST_FILESYSTEM_VERSION == 3 - std::string path = rel_path_so_far + (itr->path().filename()).string(); -#else + #if BOOST_FILESYSTEM_VERSION == 3 + std::string path = rel_path_so_far + (itr->path().filename()).string(); + #else std::string path = rel_path_so_far + (itr->path ()).filename (); -#endif + #endif std::string fullpath = rel_path_so_far + itr->path().string(); relative_paths.push_back(fullpath); } @@ -308,36 +322,40 @@ namespace od static void getFilesInDirectory(bf::path &dir, std::string &rel_path_so_far, std::vector &relative_paths, std::string const &ext) { bf::directory_iterator end_itr; - for(bf::directory_iterator itr(dir); itr != end_itr; ++itr) { + for(bf::directory_iterator itr(dir); itr != end_itr; ++itr) + { //check if its a directory, then get models in it - if(bf::is_directory(*itr)) { -#if BOOST_FILESYSTEM_VERSION == 3 - std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/"; -#else + if(bf::is_directory(*itr)) + { + #if BOOST_FILESYSTEM_VERSION == 3 + std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/"; + #else std::string so_far = rel_path_so_far + (itr->path ()).filename () + "/"; -#endif + #endif bf::path curr_path = itr->path(); getFilesInDirectoryInternal(curr_path, so_far, relative_paths, ext); - } else { + } + else + { //check that it is a ply file and then add, otherwise ignore.. std::vector strs; -#if BOOST_FILESYSTEM_VERSION == 3 - std::string file = (itr->path().filename()).string(); -#else + #if BOOST_FILESYSTEM_VERSION == 3 + std::string file = (itr->path().filename()).string(); + #else std::string file = (itr->path ()).filename (); -#endif + #endif boost::split(strs, file, boost::is_any_of(".")); std::string extension = strs[strs.size() - 1]; if( file.rfind(ext) != std::string::npos ) { -#if BOOST_FILESYSTEM_VERSION == 3 - std::string path = rel_path_so_far + (itr->path().filename()).string(); -#else + #if BOOST_FILESYSTEM_VERSION == 3 + std::string path = rel_path_so_far + (itr->path().filename()).string(); + #else std::string path = rel_path_so_far + (itr->path ()).filename (); -#endif + #endif std::string fullpath = rel_path_so_far + itr->path().string(); relative_paths.push_back(path); } From ccde7b978be4ec5fcf2a021b79a57749174944c6 Mon Sep 17 00:00:00 2001 From: vaibhavs825 Date: Wed, 27 Sep 2017 18:09:19 +0530 Subject: [PATCH 3/5] Applied standard comment style layout. --- common/pipeline/ODAlgorithmBase.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/pipeline/ODAlgorithmBase.h b/common/pipeline/ODAlgorithmBase.h index ba38a7cb..1c86e6b1 100644 --- a/common/pipeline/ODAlgorithmBase.h +++ b/common/pipeline/ODAlgorithmBase.h @@ -30,15 +30,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OPENDETECTION_ODALGORITHMBASE_H #define OPENDETECTION_ODALGORITHMBASE_H -#include +#include #include #include - namespace od { - /** \brief The base of all algorithm classes + /** \brief The base of all algorithm classes. * * \author Kripasindhu Sarkar * From 4ac1881811658370a84eb5124133ddca67baf1e7 Mon Sep 17 00:00:00 2001 From: vaibhavs825 Date: Wed, 27 Sep 2017 18:31:12 +0530 Subject: [PATCH 4/5] fixed some spelling errors. Appied standard cpp curly braces layout. Applied standard comment layout. --- common/pipeline/ObjectDetector.h | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/common/pipeline/ObjectDetector.h b/common/pipeline/ObjectDetector.h index 29bd9174..d63a6c4a 100644 --- a/common/pipeline/ObjectDetector.h +++ b/common/pipeline/ObjectDetector.h @@ -50,8 +50,7 @@ namespace od IMAGE_GLOBAL_CLASSIFICATION, }; - /** \brief The common class for detectors. Both Trainers and Detectors drerives from this and therefore, all the common data/functionalities of Trainers and Detectors should go here. - * + /** \brief The common class for detectors. Both Trainers and Detectors derives from this and therefore, all the common data/functionalities of Trainers and Detectors should go here. * * \author Kripasindhu Sarkar * @@ -63,24 +62,23 @@ namespace od ODDetectorCommon( std::string const &trained_data_location_="") : trained_data_location_(trained_data_location_) { - std::string clasname = typeid(this).name(); - TRAINED_DATA_ID_ = clasname; - std::transform(clasname.begin(), clasname.end(), clasname.begin(), ::toupper); - TRAINED_LOCATION_DENTIFIER_ = clasname; + std::string classname = typeid(this).name(); + TRAINED_DATA_ID_ = classname; + std::transform(classname.begin(), classname.end(), classname.begin(), ::toupper); + TRAINED_LOCATION_DENTIFIER_ = classname; } virtual void init() = 0; - /** \brief Gets/Sets the directory containing the data for training. The trainer uses the data from directory for training. Detectors can use this location to get additional information in its detection algirhtms as well. + /** \brief Gets/Sets the directory containing the data for training. The trainer uses the data from directory for training. + * Detectors can use this location to get additional information in its detection algirhtms as well. */ std::string getTrainingInputLocation() const { return training_input_location_; } - /** \brief Gets/Sets the directory containing the data for training. The trainer uses the data from directory for training. Detectors can use this location to get additional information in its detection algirhtms as well. - */ void setTrainingInputLocation(std::string training_input_location_) { this->training_input_location_ = training_input_location_; @@ -132,7 +130,6 @@ namespace od }; /** \brief This is the main class for object detection and recognition. - * * * \author Kripasindhu Sarkar * @@ -164,16 +161,6 @@ namespace od this->always_train_ = always_train_; } - std::string getTrainingInputLocation() const - { - return training_input_location_; - } - - void setTrainingInputLocation(std::string training_input_location_) - { - this->training_input_location_ = training_input_location_; - } - std::string getTrainingDataLocation() const { return training_data_location_; @@ -196,7 +183,6 @@ namespace od virtual int train() = 0; - virtual int detect(ODScene *scene, std::vector detections) {} virtual ODDetection* detect(ODScene *scene) {} @@ -207,7 +193,6 @@ namespace od bool always_train_; bool trained_; std::string training_input_location_, training_data_location_; - std::string TRAINED_DATA_EXT_, TRAINED_DATA_IDENTIFIER_; }; From 43637ca5cd31ad08f6b2e18c3a2e079585095718 Mon Sep 17 00:00:00 2001 From: vaibhavs825 Date: Wed, 27 Sep 2017 22:09:37 +0530 Subject: [PATCH 5/5] fixed issue #16 --- 3rdparty/SiftGPU/src/SiftGPU/GLTexImage.cpp | 114 ++++++++++---------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/3rdparty/SiftGPU/src/SiftGPU/GLTexImage.cpp b/3rdparty/SiftGPU/src/SiftGPU/GLTexImage.cpp index a6a28098..08fa1352 100644 --- a/3rdparty/SiftGPU/src/SiftGPU/GLTexImage.cpp +++ b/3rdparty/SiftGPU/src/SiftGPU/GLTexImage.cpp @@ -920,7 +920,7 @@ int GLTexInput::SetImageData( int width, int height, const void * data, { int simple_format = IsSimpleGlFormat(gl_format, gl_type);//no cpu code to handle other formats int ws, hs, done = 1; - + if(_converted_data) {delete [] _converted_data; _converted_data = NULL; } _rgb_converted = 1; @@ -1126,64 +1126,64 @@ int GLTexInput::LoadImageFile(char *imagepath, int &w, int &h ) return done; #else - FILE * file = fopen(imagepath, "rb"); if (file ==NULL) return 0; - - char buf[8]; int width, height, cn, g, done = 1; - - if(fscanf(file, "%s %d %d %d", buf, &width, &height, &cn )<4 || cn > 255 || width < 0 || height < 0) - { - fclose(file); - std::cerr << "ERROR: fileformat not supported\n"; - return 0; - }else - { - w = width; - h = height; - } - unsigned char * data = new unsigned char[width * height]; - unsigned char * pixels = data; - if (strcmp(buf, "P5")==0 ) - { - fscanf(file, "%c",buf);//skip one byte - fread(pixels, 1, width*height, file); - }else if (strcmp(buf, "P2")==0 ) - { - for (int i = 0 ; i< height; i++) - { - for ( int j = 0; j < width; j++) - { - fscanf(file, "%d", &g); - *pixels++ = (unsigned char) g; - } - } - }else if (strcmp(buf, "P6")==0 ) - { - fscanf(file, "%c", buf);//skip one byte - int j, num = height*width; - unsigned char buf[3]; - for ( j =0 ; j< num; j++) - { - fread(buf,1,3, file); - *pixels++=int(0.10454f* buf[2]+0.60581f* buf[1]+0.28965f* buf[0]); - } - }else if (strcmp(buf, "P3")==0 ) - { - int r, g, b; - int i , num =height*width; - for ( i = 0 ; i< num; i++) - { - fscanf(file, "%d %d %d", &r, &g, &b); - *pixels++ = int(0.10454f* b+0.60581f* g+0.28965f* r); - } - - }else - { - std::cerr << "ERROR: fileformat not supported\n"; - done = 0; + FILE * file = fopen(imagepath, "rb"); if (file ==NULL) return 0; + + char buf[8]; int width, height, cn, g, done = 1; + + if(fscanf(file, "%s %d %d %d", buf, &width, &height, &cn )<4 || cn > 255 || width < 0 || height < 0) + { + fclose(file); + std::cerr << "ERROR: fileformat not supported\n"; + return 0; + }else + { + w = width; + h = height; + } + unsigned char * data = new unsigned char[width * height]; + unsigned char * pixels = data; + if (strcmp(buf, "P5")==0 ) + { + fscanf(file, "%c",buf);//skip one byte + fread(pixels, 1, width*height, file); + }else if (strcmp(buf, "P2")==0 ) + { + for (int i = 0 ; i< height; i++) + { + for ( int j = 0; j < width; j++) + { + fscanf(file, "%d", &g); + *pixels++ = (unsigned char) g; + } + } + }else if (strcmp(buf, "P6")==0 ) + { + fscanf(file, "%c", buf);//skip one byte + int j, num = height*width; + unsigned char buf[3]; + for ( j =0 ; j< num; j++) + { + fread(buf,1,3, file); + *pixels++=int(0.10454f* buf[2]+0.60581f* buf[1]+0.28965f* buf[0]); + } + }else if (strcmp(buf, "P3")==0 ) + { + int r, g, b; + int i , num =height*width; + for ( i = 0 ; i< num; i++) + { + fscanf(file, "%d %d %d", &r, &g, &b); + *pixels++ = int(0.10454f* b+0.60581f* g+0.28965f* r); + } + + }else + { + std::cerr << "ERROR: fileformat not supported\n"; + done = 0; } if(done) SetImageData(width, height, data, GL_LUMINANCE, GL_UNSIGNED_BYTE); - fclose(file); - delete data; + fclose(file); + delete [] data; if(GlobalUtil::_verbose && done) std::cout<< "Image loaded :\t" << imagepath << "\n"; return 1; #endif