Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to dump files in respective bibNumber folder #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bibnumber/Debug/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ CPP_SRCS += \
../pipeline.cpp \
../textdetection.cpp \
../textrecognition.cpp \
../train.cpp
../train.cpp \
../dumpimages.cpp

OBJS += \
./batch.o \
Expand All @@ -21,7 +22,8 @@ OBJS += \
./pipeline.o \
./textdetection.o \
./textrecognition.o \
./train.o
./train.o \
./dumpimages.o

CPP_DEPS += \
./batch.d \
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions bibnumber/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <string>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/bimap.hpp>
#include <boost/bimap/set_of.hpp>
#include <boost/bimap/multiset_of.hpp>
Expand All @@ -16,6 +17,7 @@
#include "batch.h"
#include "pipeline.h"
#include "log.h"
#include "dumpimages.h"

namespace bimaps = boost::bimaps;
namespace fs = boost::filesystem;
Expand Down Expand Up @@ -243,10 +245,13 @@ int process(std::string inputName, std::string svmModel) {
bimaps::multiset_of<int> > 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<j ; i++) {
std::vector<int> bibNumbers;
Expand All @@ -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<std::string>(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 */
Expand Down
34 changes: 34 additions & 0 deletions bibnumber/dumpimages.cpp
Original file line number Diff line number Diff line change
@@ -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*/
20 changes: 20 additions & 0 deletions bibnumber/dumpimages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#ifndef BIBNUMBER_DUMPIMAGES_H
#define BIBNUMBER_DUMPIMAGES_H
#include <iostream>
#include <string>
#include <boost/filesystem.hpp>

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