...
#include < iostream> #include < opencv2\opencv.hpp> #include < opencv2\highgui.hpp> #include < opencv2\imgcodecs.hpp> #include < opencv2\core.hpp> #include < opencv2\imgproc.hpp> #include < opencv2\text.hpp> #include < opencv2/features2d.hpp> #ifdef _DEBUG #pragma comment(lib, "opencv_core300d.lib") #pragma comment(lib, "opencv_highgui300d.lib") #pragma comment(lib, "opencv_imgcodecs300d.lib") #pragma comment(lib, "opencv_text300d.lib") #pragma comment(lib, "opencv_features2d300d.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #else #pragma comment(lib, "opencv_core300.lib") #pragma comment(lib, "opencv_highgui300.lib") #pragma comment(lib, "opencv_imgcodecs300.lib") #pragma comment(lib, "opencv_text300.lib") #pragma comment(lib, "opencv_features2d300.lib") #pragma comment(lib, "opencv_imgproc300d.lib") #endif using namespace std; using namespace cv; void groups_draw(Mat &src, vector< Rect> &groups); void main() { Mat inImg = imread(".\\scenetext01.jpg"); vector< Mat> channels; text::computeNMChannels(inImg, channels); int cn = (int)channels.size(); // Append negative channels to detect ER- (bright regions over dark background) for (int c = 0; c < cn - 1; c++) channels.push_back(255 - channels[c]); Ptr< text::ERFilter> er_filter1 = text::createERFilterNM1(text::loadClassifierNM1(".\\trained_classifierNM1.xml"), 16, 0.00015f, 0.13f, 0.2f, true, 0.1f); Ptr< text::ERFilter> er_filter2 = text::createERFilterNM2(text::loadClassifierNM2(".\\trained_classifierNM2.xml"), 0.5); vector< vector< text::ERStat> > regions(channels.size()); for (int c = 0; c< (int)channels.size(); c++) { er_filter1->run(channels[c], regions[c]); er_filter2->run(channels[c], regions[c]); } // Detect character groups cout << "Grouping extracted ERs ... "; vector< vector< Vec2i> > region_groups; vector< Rect> groups_boxes; text::erGrouping(inImg, channels, regions, region_groups, groups_boxes, text::ERGROUPING_ORIENTATION_HORIZ); groups_draw(inImg, groups_boxes); imshow("grouping", inImg); waitKey(0); } 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), 3, 8); else rectangle(src, groups.at(i).tl(), groups.at(i).br(), Scalar(255), 3, 8); } }///
Thanks for the code.
ReplyDelete