Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Text Recognition

$
0
0
I have done half of Text detection using below Program, so next part is the text recognition. I would like to know how to integrate [end_to_end_recognition](https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/end_to_end_recognition.cpp) with the below code??? #include #include #include #include #include #include #include using namespace cv; using namespace std; using namespace cv::text; #define INPUT_FILE "Example3.png" #define OUTPUT_FOLDER_PATH string("C:\\Users\\\\Desktop\\Reco_Pics\\") int main(int argc, char* argv[]) { #pragma region Text Detection(OpenCV) Mat large = imread(INPUT_FILE); imshow("Original Image", large); Mat rgb; // downsample and use it for processing -- Grayscale //pyrDown(large, rgb); Mat small; //cvtColor(rgb, small, CV_BGR2GRAY); cvtColor(large, small, CV_BGR2GRAY); imshow("BGR2GRAY", small); // morphological gradient -- Morph Mat grad; Mat morphKernel = getStructuringElement(MORPH_ELLIPSE, Size(2, 2)); morphologyEx(small, grad, MORPH_GRADIENT, morphKernel); imshow("MORPH_GRADIENT", grad); // binarize -- Threshold Mat bw; threshold(grad, bw, 255.0, 255.0, THRESH_BINARY | THRESH_OTSU); imshow("Threshold", bw); // connect horizontally oriented regions -- dilate Mat connected; morphKernel = getStructuringElement(MORPH_RECT, Size(9, 1)); morphologyEx(bw, connected, MORPH_CLOSE, morphKernel); imshow("MORPH_CLOSE", connected); // find contours Mat mask = Mat::zeros(bw.size(), CV_8UC1); vector> contours; vector hierarchy; try { findContours(connected, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); imshow("Contours", connected); } catch (Exception ex) { cout << ex.what(); } // filter contours for (int idx = 0; idx >= 0; idx = hierarchy[idx][0]) { Rect rect = boundingRect(contours[idx]); Mat maskROI(mask, rect); maskROI = Scalar(0, 0, 0); // fill the contour drawContours(mask, contours, idx, Scalar(255, 255, 255), CV_FILLED); // ratio of non-zero pixels in the filled region double r = (double)countNonZero(maskROI) / (rect.width*rect.height); if (r > .05 /* assume at least 45% of the area is filled if it contains text */&& (rect.height > 8 && rect.width > 8) /* constraints on region size */ /* these two conditions alone are not very robust. better to use something like the number of significant peaks in a horizontal projection as a third condition */ ) { //rectangle(rgb, rect, Scalar(0, 255, 0), 2); rectangle(large, rect, Scalar(0, 255, 0), 2); } } //imshow("Final_Output", rgb); imshow("Final_Output", large); //imwrite(OUTPUT_FOLDER_PATH + string("_Output.jpg"), rgb); #pragma endregion waitKey(); return 0; } Any suggestion will be helpful.

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>