1 | initial version |
to solve this kind of problems i want to share an approach based on cv::erode
with the code below i tried to find text blocks. the result is OK by manuel parameters of cv::erode
cv::Mat kernel = cv::Mat::ones(10, 5, CV_8U);
erode(src_gray,src_gray, kernel, Point(-1,-1),2);
with a bit effort it is possible to develop an algorithm for manually entered values.
image after binarization and cv::erode
final result
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int, char** argv )
{
Mat src,src_gray;
src = imread("27411.jpg");
if (src.empty())
{
cerr << "No image supplied ..." << endl;
return -1;
}
cvtColor( src, src_gray, COLOR_BGR2GRAY );
src_gray = src_gray >127;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
cv::Mat kernel = cv::Mat::ones(10, 5, CV_8U);
erode(src_gray,src_gray, kernel, Point(-1,-1),2);
imshow( "src_gray", src_gray );
findContours( src_gray, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE, Point(0, 0) );
for( size_t i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( 0,255,0 );
Rect R = boundingRect(Mat(contours[i]));
rectangle(src,R,color);
}
imshow( "result", src );
waitKey(0);
return(0);
}