Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlyqing00 committed Oct 30, 2018
1 parent 9b417c8 commit 4d6164a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
13 changes: 12 additions & 1 deletion include/stripes_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class Stripes {

public:

enum Metric {
PIXEL,
CHAR,
WORD
};

enum Composition {
GREEDY,
TSP,
Expand All @@ -39,7 +45,9 @@ class Stripes {

void push(const cv::Mat & stripe_img);

bool reassemble(Composition comp_mode);
bool reassemble(Metric _metric_mode, Composition comp_mode);

double m_metric_pixel(const Fragment & frag0, const Fragment & frag1);

double m_metric_word(const Fragment & frag0, const Fragment & frag1);

Expand All @@ -51,8 +59,11 @@ class Stripes {

cv::Mat merge_frags(const cv::Mat & in_frag0, const cv::Mat & in_frag1);

Metric metric_mode;
bool reassemble_greedy();

double diff_vec3b(const cv::Vec3b & v0, const cv::Vec3b & v1);

bool cross_seam(const cv::Rect & bbox, int seam_x);

bool detect_new_word( const string & word,
Expand Down
5 changes: 3 additions & 2 deletions src/solve_stripes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ int main(int argc, char ** argv) {
// Default parameters
string case_name = "test0";
int stripes_n = 4;
Stripes::Composition comp_mod = Stripes::GREEDY;
Stripes::Composition comp_mode = Stripes::GREEDY;
Stripes::Metric metric_mode = Stripes::PIXEL;
string model_path = "data/models/";

// Parse command line parameters
Expand Down Expand Up @@ -43,7 +44,7 @@ int main(int argc, char ** argv) {
stripes.push(stripe_img);
}

stripes.reassemble(comp_mod);
stripes.reassemble(metric_mode, comp_mode);
stripes.save_result(case_name);
for (const int idx: stripes.comp_idx) {
cout << idx << endl;
Expand Down
44 changes: 42 additions & 2 deletions src/stripes_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ void Stripes::push(const cv::Mat & stripe_img) {
stripes_n = stripes.size();
}

bool Stripes::reassemble(Composition comp_mode) {
bool Stripes::reassemble(Metric _metric_mode, Composition comp_mode) {

metric_mode = _metric_mode;

switch (comp_mode) {
case Stripes::GREEDY:
cout << "Reassemble mode: \t" << "GREEDY" << endl;
Expand All @@ -55,6 +57,29 @@ bool Stripes::reassemble(Composition comp_mode) {

}

double Stripes::diff_vec3b(const cv::Vec3b & v0, const cv::Vec3b & v1) {

double diff = 0;
for (int i = 0; i < 3; i++) diff += abs(v0[i] - v1[i]);
return diff / 3;

}

double Stripes::m_metric_pixel(const Fragment & frag0, const Fragment & frag1) {

int x0 = frag0.size.width - 1;
int x1 = 0;

double m_score = 0;
for (int y = 0; y < frag0.size.height; y++) {
m_score += diff_vec3b( frag0.img.at<cv::Vec3b>(x0, y),
frag0.img.at<cv::Vec3b>(x1, y));
}

return m_score;

}

double Stripes::m_metric_word(const Fragment & frag0, const Fragment & frag1) {

cv::Mat && merged_img = merge_frags(frag0.img, frag1.img);
Expand Down Expand Up @@ -201,9 +226,24 @@ bool Stripes::reassemble_greedy() {
vector<StripePair> stripe_pairs;
for (int i = 0; i < stripes_n; i++) {
for (int j = 0; j < stripes_n; j++) {

if (i == j) continue;
StripePair sp(i, j, m_metric_word(frags[i], frags[j]));

double m_score = 0;
switch (metric_mode) {
case PIXEL:
m_score = m_metric_pixel(frags[i], frags[j]);
break;
case CHAR:
break;
case WORD:
m_score = m_metric_word(frags[i], frags[j]);
break;
}

StripePair sp(i, j, m_score);
stripe_pairs.push_back(sp);

}
}

Expand Down

0 comments on commit 4d6164a

Please sign in to comment.