Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlyqing00 committed Dec 12, 2018
1 parent 6d75fbd commit 4ac9b40
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
1 change: 0 additions & 1 deletion include/stripes_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class StripesSolver {
int sols_n = 10;
vector< vector<double> > pixel_graph;

double m_metric_pixel(const cv::Mat & piece0, const cv::Mat & piece1);
double m_metric_word(const cv::Mat & piece0, const cv::Mat & piece1);
double m_metric_comp_eva(const cv::Mat & piece0, const cv::Mat & piece1);

Expand Down
5 changes: 3 additions & 2 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ enum class PuzzleType {

const double eps = 1e-8;
const int U_a = 5;
const cv::Scalar boundary_color(50, 50, 255);
const cv::Scalar seam_color_red(100, 100, 200);
const cv::Scalar seam_color_green(100, 200, 100);

double avg_vec3b(const cv::Vec3b &v);

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

double m_metric_pixel(const cv::Mat & img0, const cv::Mat & img1);
double m_metric_pixel(const cv::Mat & piece0, const cv::Mat & piece1);

cv::Mat merge_imgs(const cv::Mat & in_img0, const cv::Mat & in_img1);

Expand Down
6 changes: 3 additions & 3 deletions src/debug_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool show_counter_example_pixel_metric( const cv::Mat & root_img,
cv::line( canvas,
cv::Point(root_img.cols, 0),
cv::Point(root_img.cols, root_img.rows),
boundary_color,
seam_color_green,
1);

// matching score between root and test.
Expand All @@ -68,7 +68,7 @@ bool show_counter_example_pixel_metric( const cv::Mat & root_img,
cv::line( canvas,
cv::Point(root_img.cols * 3 + indication_width * 3 + 1, 0),
cv::Point(root_img.cols * 3 + indication_width * 3 + 1, root_img.rows),
boundary_color,
seam_color_red,
1);

// root
Expand Down Expand Up @@ -185,7 +185,7 @@ bool show_counter_example_ocr_char_metric( const cv::Mat & root_img,
cv::line( canvas,
cv::Point(root_img.cols, 0),
cv::Point(root_img.cols, root_img.rows),
boundary_color,
seam_color_red,
1);

// root
Expand Down
37 changes: 2 additions & 35 deletions src/solver/stripes_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ cv::Mat StripesSolver::compose_img(const vector<int> & composition_order) {

cv::Mat StripesSolver::add_seams(const cv::Mat & img, const vector<int> & composition_order) {

const cv::Scalar color_red(100, 100, 200);
const cv::Scalar color_green(100, 200, 100);
cv::Mat img_seams = img.clone();
int col = stripes[composition_order[0]].cols;
cv::Scalar seam_color;
Expand All @@ -130,9 +128,9 @@ cv::Mat StripesSolver::add_seams(const cv::Mat & img, const vector<int> & compos
for (int j = 0; j < stripes_n; j++) {
if (gt_order[j] != composition_order[i-1]) continue;
if (j == stripes_n - 1 || gt_order[j+1] != composition_order[i]) {
seam_color = color_red;
seam_color = seam_color_red;
} else {
seam_color = color_green;
seam_color = seam_color_green;
}
break;
}
Expand All @@ -146,37 +144,6 @@ cv::Mat StripesSolver::add_seams(const cv::Mat & img, const vector<int> & compos

}


double StripesSolver::m_metric_pixel(const cv::Mat & piece0, const cv::Mat & piece1) {

assert(piece0.rows == piece1.rows);

int x0 = piece0.cols - 1;
int x1 = 0;

double m_score = 0;
double avg_pixel_color0 = 0;
double avg_pixel_color1 = 0;
for (int y = 0; y < piece0.rows; y++) {
double avg_vec3b0 = avg_vec3b(piece0.at<cv::Vec3b>(y, x0));
double avg_vec3b1 = avg_vec3b(piece1.at<cv::Vec3b>(y, x1));
m_score += abs(avg_vec3b0 - avg_vec3b1);
avg_pixel_color0 += avg_vec3b0;
avg_pixel_color1 += avg_vec3b1;
}

avg_pixel_color0 /= piece0.rows;
avg_pixel_color1 /= piece0.rows;
m_score /= piece0.rows;

if (max(avg_pixel_color0, avg_pixel_color1) < 15 ||
min(avg_pixel_color0, avg_pixel_color1) > 240) {
return -1;
}
return m_score;

}

double StripesSolver::m_metric_word(const cv::Mat & piece0, const cv::Mat & piece1) {

cv::Mat && merged_img = merge_imgs(piece0, piece1);
Expand Down
27 changes: 21 additions & 6 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ double diff_vec3b(const cv::Vec3b & v0, const cv::Vec3b & v1) {

}

double m_metric_pixel(const cv::Mat & img0, const cv::Mat & img1) {
double m_metric_pixel(const cv::Mat & piece0, const cv::Mat & piece1) {

int x0 = img0.cols - 1;
assert(piece0.rows == piece1.rows);

int x0 = piece0.cols - 1;
int x1 = 0;

double m_score = 0;
for (int y = 0; y < img0.rows; y++) {
m_score += diff_vec3b( img0.at<cv::Vec3b>(y, x0),
img1.at<cv::Vec3b>(y, x1));
double avg_pixel_color0 = 0;
double avg_pixel_color1 = 0;
for (int y = 0; y < piece0.rows; y++) {
double avg_vec3b0 = avg_vec3b(piece0.at<cv::Vec3b>(y, x0));
double avg_vec3b1 = avg_vec3b(piece1.at<cv::Vec3b>(y, x1));
m_score += abs(avg_vec3b0 - avg_vec3b1);
avg_pixel_color0 += avg_vec3b0;
avg_pixel_color1 += avg_vec3b1;
}

return -m_score / img0.rows;
avg_pixel_color0 /= piece0.rows;
avg_pixel_color1 /= piece0.rows;
m_score /= piece0.rows;

if (max(avg_pixel_color0, avg_pixel_color1) < 15 ||
min(avg_pixel_color0, avg_pixel_color1) > 240) {
return -1;
}
return m_score;

}

Expand Down

0 comments on commit 4ac9b40

Please sign in to comment.