I use opencv_contrib to detect text areas in the image.
This is the original image.
This image is after the text areas are found:
As you can see, there are overlapping groups in the image. For example, it seems that there are two groups around Hello World and two around Some more sample text
Question In scenarios like this, I can save the maximum possible box by combining the two fields. For these examples, which will start with H and end with d so that it covers Hello World . My reason is that I would like to crop part of this image and send it to tesseract.
Here is the corresponding code that draws the fields.
void groups_draw(Mat &src, vector<Rect> &groups) { for (int i=(int)groups.size()-1; i>=0; i--) { if (src.type() == CV_8UC3) rectangle(src,groups.at(i).tl(),groups.at(i).br(),Scalar( 0, 255, 255 ), 2, 8 ); } }
Here is what I have tried. My ideas in the comments.
void groups_draw(Mat &src, vector<Rect> &groups) { int previous_tl_x = 0; int previous_tl_y = 0; int prevoius_br_x = 0; int previous_br_y = 0;
Update
I am trying to use [groupRectangles][4] to accomplish this:
void groups_draw(Mat &src, vector<Rect> &groups) { vector<Rect> rects; for (int i=(int)groups.size()-1; i>=0; i--) { rects.push_back(groups.at(i)); } groupRectangles(rects, 1, 0.2); }
However, this gives me an error:
textdetection.cpp:106:5: error: use of undeclared identifier 'groupRectangles' groupRectangles(rects, 1, 0.2); ^ 1 error generated.