Skip to content

Commit

Permalink
divide generator and solver
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlyqing00 committed Oct 30, 2018
1 parent 11254eb commit bb28212
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 136 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
*.o
*.d
StripeReassembly
StripeReassembly-debug

/bin/
/data/stripes/
/data/results/

Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,33 @@ OPENCV_LIBS = -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video
TESSARACT_LIBS = -ltesseract

src_dir = ./src/
dst_dir = ./
dst_dir = ./bin/
src = $(wildcard $(src_dir)*.cpp)
obj = $(src:.cpp=.o)
obj_debug = $(src:.cpp=.debug.o)
dep = $(src:.cpp=.d)

.PHONY: clean default debug
default: StripeReassembly
debug: StripeReassembly-debug
c_stripes = $(src_dir)create_stripes.o \
$(src_dir)stripes_generator.o

s_stripes = $(src_dir)solve_stripes.o \
$(src_dir)stripes.o \
$(src_dir)stripe_pair.o \
$(src_dir)fragment.o

%.debug.o: %.cpp
$(CXX) -c $< -o $@ -MMD -DDEBUG $(CXX_FLAGS) $(INCLUDES)
.PHONY: clean default
default: solve-stripes create-stripes

%.o: %.cpp
$(CXX) -c $< -o $@ -MMD $(CXX_FLAGS) $(INCLUDES)

-include $(dep)

StripeReassembly-debug: $(obj_debug)
$(CXX) $^ $(TESSARACT_LIBS) $(OPENCV_LIBS) -DDEBUG -o $(dst_dir)$@
create-stripes: $(c_stripes)
$(CXX) $^ $(OPENCV_LIBS) -o $(dst_dir)$@

StripeReassembly: $(obj)
solve-stripes: $(s_stripes)
$(CXX) $^ $(TESSARACT_LIBS) $(OPENCV_LIBS) -o $(dst_dir)$@

clean:
rm $(dst)StripeReassembly $(dst)StripeReassembly-debug $(src_dir)*.o $(src_dir)*.d
rm $(dst)create-stripes $(dst)solve-stripes $(src_dir)*.o $(src_dir)*.d

15 changes: 15 additions & 0 deletions include/create_stripes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef CREATE_STRIPES_H
#define CREATE_STRIPES_H

#include <unistd.h>
#include <string>
#include <iostream>

#include <opencv2/opencv.hpp>

#include <stripes_generator.h>

using namespace std;


#endif
5 changes: 2 additions & 3 deletions include/main.h → include/solve_stripes.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef MAIN_H
#define MAIN_H
#ifndef SOLVE_STRIPES
#define SOLVE_STRIPES

#include <unistd.h>
#include <string>
#include <opencv2/opencv.hpp>

#include <stripes.h>
#include <stripes_generator.h>

using namespace std;

Expand Down
50 changes: 50 additions & 0 deletions src/create_stripes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <create_stripes.h>


int main(int argc, char ** argv) {

// Default parameters
string case_name = "test0";
int stripes_n = 4;
bool generate_flag = false;

// Parse command line parameters
const string opt_str = "t:T:n:N:gG";
int opt = getopt(argc, argv, opt_str.c_str());

while (opt != -1) {
switch (opt) {
case 't': case 'T':
case_name = string(optarg);
break;
case 'n': case 'N':
stripes_n = atoi(optarg);
break;
case 'g': case 'G':
generate_flag = true;
break;
}

opt = getopt(argc, argv, opt_str.c_str());
}

cout << "Case name:\t\t" << case_name << endl;
cout << "Stripes num:\t\t" << stripes_n << endl;
cout << "Generate stripes:\t" << boolalpha << generate_flag << endl;
cout << endl;

// Generate new stripes
const string stripes_folder = "data/stripes/" + case_name + "_" + to_string(stripes_n) + "/";

if (generate_flag || access(stripes_folder.c_str(), 0) == -1) {
const string gt_folder = "data/gt/";
const string gt_img_path = gt_folder + case_name + ".png";
cv::Mat gt_img = cv::imread(gt_img_path);

StripesGenerator stripes_generator(gt_img_path, stripes_n);
stripes_generator.save_stripes(stripes_folder);
}

return 0;

}
120 changes: 0 additions & 120 deletions src/main.cpp

This file was deleted.

56 changes: 56 additions & 0 deletions src/solve_stripes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <solve_stripes.h>

int main(int argc, char ** argv) {

// Default parameters
string case_name = "test0";
int stripes_n = 4;
Stripes::Composition comp_mod = Stripes::GREEDY;
string model_path = "data/models/";

// Parse command line parameters
const string opt_str = "t:T:n:N:m:M:";
int opt = getopt(argc, argv, opt_str.c_str());

while (opt != -1) {
switch (opt) {
case 't': case 'T':
case_name = string(optarg);
break;
case 'n': case 'N':
stripes_n = atoi(optarg);
break;
case 'm': case 'M':
model_path = string(optarg);
break;
}

opt = getopt(argc, argv, opt_str.c_str());
}

cout << "Case name:\t\t" << case_name << endl;
cout << "Stripes num:\t\t" << stripes_n << endl;
cout << "OCR model path:\t\t" << model_path << endl;
cout << endl;

// Import stripes
const string stripes_folder = "data/stripes/" + case_name + "_" + to_string(stripes_n) + "/";
Stripes stripes(model_path);

for (int i = 0; i < stripes_n; i++) {
const string stripe_img_path = stripes_folder + to_string(i) + ".png";
cv::Mat stripe_img = cv::imread(stripe_img_path);
stripes.push(stripe_img);
}

stripes.reassemble(comp_mod);
stripes.save_result(case_name);
for (const int idx: stripes.comp_idx) {
cout << idx << endl;
}

cv::imshow("comp_img", stripes.comp_img);
cv::waitKey();

return 0;
}

0 comments on commit bb28212

Please sign in to comment.