From e05a6783fa2c0779f234740b86da3c9752d413e8 Mon Sep 17 00:00:00 2001 From: Rohit Takhar Date: Tue, 3 Apr 2018 17:00:12 +0530 Subject: [PATCH 1/2] Added functionality to dump files in respective bibNumber folder --- bibnumber/Debug/subdir.mk | 9 ++++++--- bibnumber/batch.cpp | 16 ++++++++++++++++ bibnumber/dumpimages.cpp | 34 ++++++++++++++++++++++++++++++++++ bibnumber/dumpimages.h | 20 ++++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 bibnumber/dumpimages.cpp create mode 100644 bibnumber/dumpimages.h diff --git a/bibnumber/Debug/subdir.mk b/bibnumber/Debug/subdir.mk index 44ffc8c..06ad51e 100644 --- a/bibnumber/Debug/subdir.mk +++ b/bibnumber/Debug/subdir.mk @@ -11,7 +11,8 @@ CPP_SRCS += \ ../pipeline.cpp \ ../textdetection.cpp \ ../textrecognition.cpp \ -../train.cpp +../train.cpp \ +../dumpimages.cpp OBJS += \ ./batch.o \ @@ -21,7 +22,8 @@ OBJS += \ ./pipeline.o \ ./textdetection.o \ ./textrecognition.o \ -./train.o +./train.o \ +./dumpimages.o CPP_DEPS += \ ./batch.d \ @@ -31,7 +33,8 @@ CPP_DEPS += \ ./pipeline.d \ ./textdetection.d \ ./textrecognition.d \ -./train.d +./train.d \ +./dumpimages.d # Each subdirectory must supply rules for building sources it contributes diff --git a/bibnumber/batch.cpp b/bibnumber/batch.cpp index ba184e7..4ac9c60 100644 --- a/bibnumber/batch.cpp +++ b/bibnumber/batch.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include "batch.h" #include "pipeline.h" #include "log.h" +#include "dumpimages.h" namespace bimaps = boost::bimaps; namespace fs = boost::filesystem; @@ -243,10 +245,13 @@ int process(std::string inputName, std::string svmModel) { bimaps::multiset_of > imgTagBimap; imgTagBimap tags; + bool file_dump_flag; /* find images in directory */ img_paths = getImageFiles(inputName); + dumpimages::dumpFiles dumpObj; + /* process images */ for (int i = 0, j=img_paths.size(); i bibNumbers; @@ -257,7 +262,18 @@ int process(std::string inputName, std::string svmModel) { for (unsigned int k = 0; k < bibNumbers.size(); k++) { tags.insert( imgTagBimap::value_type(img_paths[i].string(), bibNumbers[k])); + file_dump_flag = dumpObj.dumpImages(boost::lexical_cast(bibNumbers[k]), img_paths[i]); } + + if(bibNumbers.size() == 0) + { + file_dump_flag = dumpObj.dumpImages(dumpObj.NOT_FOUND, img_paths[i]); + } + + if(file_dump_flag) + { + std::cout << "Success in copying file." << std::endl; + } } /* save results to .csv file */ diff --git a/bibnumber/dumpimages.cpp b/bibnumber/dumpimages.cpp new file mode 100644 index 0000000..79d45b0 --- /dev/null +++ b/bibnumber/dumpimages.cpp @@ -0,0 +1,34 @@ + +#include "dumpimages.h" +namespace fs = boost::filesystem; + +namespace dumpimages { + + bool dumpFiles::dumpImages(std::string bibNumber, fs::path imageName) + { + fs::path pathname(imageName); + fs::path dirname = pathname.parent_path(); + fs::path file(imageName); + fs::path full_path = dirname / file; + std::string bibPath = dirname.string() + "/"+ bibNumber; + if(!fs::exists(bibPath)) + { + if(boost::filesystem::create_directory(bibPath)) + { + std::cout << "Folder successfully created: " + bibNumber << std::endl; + } + } + + + fs::path bibPathDir(bibPath); + try { + fs::copy_file(pathname, bibPathDir / pathname.filename()); + } + catch(fs::filesystem_error const & e) + { + std:: cerr << e.what() << '\n'; + return false; + } + return true; + } +} /* namespace dumpimages*/ \ No newline at end of file diff --git a/bibnumber/dumpimages.h b/bibnumber/dumpimages.h new file mode 100644 index 0000000..cfeb7a1 --- /dev/null +++ b/bibnumber/dumpimages.h @@ -0,0 +1,20 @@ + +#ifndef BIBNUMBER_DUMPIMAGES_H +#define BIBNUMBER_DUMPIMAGES_H +#include +#include +#include + +namespace dumpimages +{ + class dumpFiles { + public: + bool dumpImages(std::string bibNumber, boost::filesystem::path imageName); + std::string NOT_FOUND; + + dumpFiles(){ + NOT_FOUND = "NOT_FOUND"; + } + }; +} +#endif //BIBNUMBER_DUMPIMAGES_H From fb489ae325b3b6273ba2390a2d704e09a1d19b8a Mon Sep 17 00:00:00 2001 From: Rohit Takhar Date: Tue, 3 Apr 2018 19:33:23 +0530 Subject: [PATCH 2/2] Corrected indentation issues --- bibnumber/batch.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bibnumber/batch.cpp b/bibnumber/batch.cpp index 4ac9c60..5af31ab 100644 --- a/bibnumber/batch.cpp +++ b/bibnumber/batch.cpp @@ -245,7 +245,7 @@ int process(std::string inputName, std::string svmModel) { bimaps::multiset_of > imgTagBimap; imgTagBimap tags; - bool file_dump_flag; + bool file_dump_flag; /* find images in directory */ img_paths = getImageFiles(inputName); @@ -265,15 +265,15 @@ int process(std::string inputName, std::string svmModel) { file_dump_flag = dumpObj.dumpImages(boost::lexical_cast(bibNumbers[k]), img_paths[i]); } - if(bibNumbers.size() == 0) - { - file_dump_flag = dumpObj.dumpImages(dumpObj.NOT_FOUND, img_paths[i]); - } + if(bibNumbers.size() == 0) + { + file_dump_flag = dumpObj.dumpImages(dumpObj.NOT_FOUND, img_paths[i]); + } - if(file_dump_flag) - { - std::cout << "Success in copying file." << std::endl; - } + if(file_dump_flag) + { + std::cout << "Success in copying file." << std::endl; + } } /* save results to .csv file */