How to translate this image processing from Matlab to OpenCV?

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); // create the feature detector

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: enter image description here

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

enter image description here

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);
    //imgMat1 = ImageUtilities.Convert2BW(imgMat1);
    String outImgName1 = picDir + "_CANNY_" + imgName1 + ".tif";
    Mat outImg1 = new Mat();
    Imgproc.Canny(imgMat1, outImg1, 0, 500);
    Imgcodecs.imwrite(outImgName1, outImg1);
}

canny edge : enter image description here

ADD 3 - VS 2013

OpenCV VS2013, .

ADD 4 - V++ 2013

, .

//Step2: Detect MSER regions
Mat grayImage;
cvtColor(colorImage, grayImage, CV_BGR2GRAY);
imshow("Gray Image", grayImage);
waitKey(0);


Ptr<MSER> mserExtractor = MSER::create(); // create MSER extractor with default parameters. http://code.opencv.org/projects/opencv/wiki/MSER http://docs.opencv.org/master/d3/d28/classcv_1_1MSER.html#a49d72a1346413106516a7fc6d95c09bb
mserExtractor->setMinArea(150);
mserExtractor->setMaxArea(2000);
//Mat mserOutMask = Mat::zeros(grayImage.rows, grayImage.cols, CV_8UC3);

Mat vis;
//vis = Mat::zeros(grayImage.rows, grayImage.cols, CV_8UC3);
grayImage.copyTo(vis);

vector<vector<Point>> mserContours;
vector<Rect> mserBBox;//what this?
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 enter image description here

vis2 - MSER by points enter image description here

5

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

enter image description here

+4
1

, OpenCV

enter image description here

, , , OCRHMMDecoder

+2

Source: https://habr.com/ru/post/1598714/


All Articles