Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
yq committed Nov 5, 2018
1 parent b597095 commit 30974e2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 24 deletions.
3 changes: 3 additions & 0 deletions include/squares_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class SquaresSolver {
private:
tesseract::TessBaseAPI * ocr;

cv::Mat merge_squares(const cv::Mat & in_img0, const cv::Mat & in_img1, Splice splice);

double m_metric_pixel(const cv::Mat & square0, const cv::Mat & square1, Splice splice);
double m_metric_symbol(const cv::Mat & square0, const cv::Mat & square1, Splice splice);
};

#endif
5 changes: 2 additions & 3 deletions include/stripes_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class StripesSolver {
GREEDY,
};

const tesseract::PageIteratorLevel tesseract_level {tesseract::RIL_WORD};
const double conf_thres {80};
string model_path;

Expand All @@ -56,8 +55,6 @@ class StripesSolver {

tesseract::TessBaseAPI * ocr;

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

Metric metric_mode;
bool reassemble_greedy();

Expand All @@ -71,6 +68,8 @@ class StripesSolver {
const double overlap_thres {0.3};
double overlap(const cv::Rect & rect0, const cv::Rect & rect1, const int offset_x=0);

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

};

#endif
48 changes: 46 additions & 2 deletions src/squares_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void SquaresSolver::push(const cv::Mat & square_img) {
void SquaresSolver::reassemble() {

square_size = squares.front().size();

for (int i = 0; i < squares_n; i++) {
for (int j = 0; j < squares_n; j++) {
if (i == j) continue;
Expand All @@ -41,7 +41,44 @@ void SquaresSolver::reassemble() {

}

double SquaresSolver::m_metric_pixel(const cv::Mat & square0, const cv::Mat & square1, SquaresSolver::Splice splice) {
cv::Mat SquaresSolver::merge_squares(const cv::Mat & in_img0, const cv::Mat & in_img1, Splice splice) {

cv::Size out_img_size;
cv::Rect in_img0_roi;
cv::Rect in_img1_roi;

switch (splice) {
case SquaresSolver::L:
out_img_size = cv::Size(square_size.width << 1, square_size.height);
in_img0_roi = cv::Rect(square_size.width, 0, square_size.width, square_size.height);
in_img1_roi = cv::Rect(0, 0, square_size.width, square_size.height);
break;
case SquaresSolver::R:
out_img_size = cv::Size(square_size.width << 1, square_size.height);
in_img0_roi = cv::Rect(0, 0, square_size.width, square_size.height);
in_img1_roi = cv::Rect(square_size.width, 0, square_size.width, square_size.height);
break;
case SquaresSolver::T:
out_img_size = cv::Size(square_size.width, square_size.height << 1);
in_img0_roi = cv::Rect(0, square_size.height, square_size.width, square_size.height);
in_img1_roi = cv::Rect(0, 0, square_size.width, square_size.height);
break;
case SquaresSolver::B:
out_img_size = cv::Size(square_size.width, square_size.height << 1);
in_img0_roi = cv::Rect(0, 0, square_size.width, square_size.height);
in_img1_roi = cv::Rect(0, square_size.height, square_size.width, square_size.height);
break;
}

cv::Mat out_img(out_img_size, CV_8UC3);
in_img0.copyTo(out_img(in_img0_roi));
in_img1.copyTo(out_img(in_img1_roi));

return out_img;

}

double SquaresSolver::m_metric_pixel(const cv::Mat & square0, const cv::Mat & square1, Splice splice) {

double m_score = 0;

Expand Down Expand Up @@ -70,4 +107,11 @@ double SquaresSolver::m_metric_pixel(const cv::Mat & square0, const cv::Mat & sq

return m_score / square_size.height;

}

double SquaresSolver::m_metric_symbol(const cv::Mat & square0, const cv::Mat & square1, Splice splice) {

cv::Mat && merged_img = merge_squares(square0, square1, splice);
double m_score = 0;
return m_score;
}
39 changes: 20 additions & 19 deletions src/stripes_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,30 @@ double StripesSolver::m_metric_pixel(const Fragment & frag0, const Fragment & fr

}

cv::Mat StripesSolver::merge_imgs(const cv::Mat & in_img0, const cv::Mat & in_img1) {

assert(in_img0.rows == in_img1.rows);

cv::Size out_img_size(in_img0.cols + in_img1.cols, in_img0.rows);
cv::Mat out_img(out_img_size, CV_8UC3);

cv::Rect in_img0_roi(0, 0, in_img0.cols, in_img0.rows);
in_img0.copyTo(out_img(in_img0_roi));

cv::Rect in_img1_roi(in_img0.cols, 0, in_img1.cols, in_img1.rows);
in_img1.copyTo(out_img(in_img1_roi));

return out_img;

}

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

cv::Mat && merged_img = merge_frags(frag0.img, frag1.img);
cv::Mat merged_img = merge_imgs(frag0.img, frag1.img);

const int seam_x = frag0.size.width;
const int max_m_width = min(frag0.size.width, frag1.size.width);
const tesseract::PageIteratorLevel tesseract_level {tesseract::RIL_WORD};

ocr->SetImage(merged_img.data, merged_img.cols, merged_img.rows, 3, merged_img.step);
ocr->SetRectangle(seam_x - max_m_width, 0, max_m_width << 1, frag0.size.height);
Expand Down Expand Up @@ -126,23 +144,6 @@ double StripesSolver::m_metric_word(const Fragment & frag0, const Fragment & fra

}

cv::Mat StripesSolver::merge_frags(const cv::Mat & in_frag0, const cv::Mat & in_frag1) {

assert(in_frag0.rows == in_frag1.rows);

cv::Size out_frag_size(in_frag0.cols + in_frag1.cols, in_frag0.rows);
cv::Mat out_frag(out_frag_size, CV_8UC3);

cv::Rect in_frag0_roi(0, 0, in_frag0.cols, in_frag0.rows);
in_frag0.copyTo(out_frag(in_frag0_roi));

cv::Rect in_frag1_roi(in_frag0.cols, 0, in_frag1.cols, in_frag1.rows);
in_frag1.copyTo(out_frag(in_frag1_roi));

return out_frag;

}

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

if (bbox.x < seam_x && bbox.x + bbox.width >= seam_x) {
Expand Down Expand Up @@ -286,7 +287,7 @@ bool StripesSolver::reassemble_greedy() {

while (stripe_right[order_idx] != -1) {
order_idx = stripe_right[order_idx];
comp_img = merge_frags(comp_img, stripes[order_idx]);
comp_img = merge_imgs(comp_img, stripes[order_idx]);
comp_idx.push_back(order_idx);
}

Expand Down

0 comments on commit 30974e2

Please sign in to comment.