The link below uses Matlab to remove non-text content from an image. I want to do the same with OpenCV in Java.
I don't have Matlab to try, and I'm new to OpenCV. Although I know some of the basics of the theory behind the process, it’s difficult to translate from Matlab into OpenCV 3.0. And preferably in Java.
http://www.mathworks.com/help/vision/examples/automatically-detect-and-recognize-text-in-natural-images.html
ADD 1 - Area Discovery Using MSER (not yet allowed)
To detect MSER, I can use the following code to detect MSER key points.
public static void MSERdetector(String imgName1, String suffix1) {
Mat imgMat1 = Imgcodecs.imread(picDir + imgName1 + "." + suffix1, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
String outImgName1 = picDir + "MSER" + "_keypoints_" + imgName1 + "_" + ".tif";
Mat outImg1 = new Mat();
FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.MSER);
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
featureDetector.detect(imgMat1, keypoints1);
if (!keypoints1.empty()) {
Features2d.drawKeypoints(imgMat1, keypoints1, outImg1);
Imgcodecs.imwrite(outImgName1, outImg1);
System.out.println("done");
}
else {
System.out.println("No keypoints found for: " + imgName1);
}
}
And the result is as follows:

But I do not know how to convert key points to regions. What I need below:

ADD 2 - Canny edge MSER ( )
MSER, intersect it with Canny edges. Canny, . , intersection.
public static void CANNYedge(String imgName1, String suffix1) {
Mat imgMat1 = Imgcodecs.imread(picDir + imgName1 + "." + suffix1, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
String outImgName1 = picDir + "_CANNY_" + imgName1 + ".tif";
Mat outImg1 = new Mat();
Imgproc.Canny(imgMat1, outImg1, 0, 500);
Imgcodecs.imwrite(outImgName1, outImg1);
}
canny edge :

ADD 3 - VS 2013
OpenCV VS2013, .
ADD 4 - V++ 2013
, .
Mat grayImage;
cvtColor(colorImage, grayImage, CV_BGR2GRAY);
imshow("Gray Image", grayImage);
waitKey(0);
Ptr<MSER> mserExtractor = MSER::create();
mserExtractor->setMinArea(150);
mserExtractor->setMaxArea(2000);
Mat vis;
grayImage.copyTo(vis);
vector<vector<Point>> mserContours;
vector<Rect> mserBBox;
mserExtractor->detectRegions(grayImage, mserContours, mserBBox);
for (int i = 0; i<mserContours.size(); i++)
{
drawContours(vis, mserContours, i, Scalar(255, 255, 255), 4);
}
imshow("MSER by contours", vis);
waitKey(0);
Mat vis2;
grayImage.copyTo(vis2);
for (vector<cv::Point> v : mserContours){
for (cv::Point p : v){
vis2.at<uchar>(p.y, p.x) = 255;
}
}
imshow("MSER by points", vis);
waitKey(0);
:
vis1 - MSER by contours

vis2 - MSER by points

5
, Miki.
. 2 , , . - OCR (, ). . . :
