1

Recently, i got a problem about OpenCV MSER detection.
The text in below image is not extracted corretly.

Image link - mser detection not work well

After morphology closing, the result seems to be right.

Code:

int main()
{
    // load
    cv::Mat sourceImage = cv::imread("F:\\Documents\\mQvnv.jpg");
    // convert
    cv::Mat grayImage;
    cv::cvtColor(sourceImage, grayImage, CV_BGR2GRAY);
    // morph close
    cv::Mat morphImage;
    cv::Mat morphKernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2 * 1 + 1, 1), cv::Point(-1, -1));
    cv::morphologyEx(grayImage, morphImage, cv::MORPH_CLOSE, morphKernel);
    // mser
    std::vector<std::vector<cv::Point> > contours;
    cv::MSER ms;
    ms(morphImage, contours);
    // show
    cv::Mat finalImage = sourceImage.clone();
    for (int idx = 0; idx < contours.size(); idx++)
    {
        // filter
        cv::RotatedRect minRect = cv::minAreaRect(contours[idx]);
        if (minRect.size.height < 4. || minRect.size.width < 4.) continue;// filter 1

        double hwr = minRect.size.height / minRect.size.width;
        if (hwr < 1.) hwr = minRect.size.width / minRect.size.height;
        if (hwr > 10.) continue;// filter 2

        double contourArea = cv::contourArea(contours[idx]);
        double rectArea = minRect.size.area();
        double areaRatio = contourArea / rectArea;
        if (areaRatio < 0.35) continue;// filter 3

        // draw rotated rectangle
        cv::Point2f rect_points[4]; minRect.points(rect_points);
        for (int j = 0; j < 4; j++)
            cv::line(finalImage, rect_points[j], rect_points[(j + 1) % 4], cv::Scalar(0, 0, 255));
    }

    cv::imshow("MSER Demo", finalImage);
    //
    cv::waitKey(0);
    return 0;
}


I'm confused.

  • Does MSER have constrains/limitations?
  • Does it need some pre-processing? What kind of? Like morphology.

I'm also looking forward new method for this type of text detection.

I appreciate it if it could be answered.

leonmy
  • 11
  • 3
  • if you provide the code you tried we also try and see the result – sturkmen Jul 27 '17 at 15:09
  • @sturkmen thanks for your reply. After that, i tried a few days, and found this [link](https://stackoverflow.com/questions/23506105/extracting-text-opencv/23672571#23672571) . It works, seems better than MSER. btw i added my code. – leonmy Jul 28 '17 at 07:10

1 Answers1

0

You have white text on a black background. Some MSER implementations look for black on a white background.

Try inverting your image and trying again.

Ted
  • 1
  • Thanks! Well, I've tried what u said. Unfortunately, seems no improvement. I use **OpenCV 2.4.13** – leonmy Jul 28 '17 at 07:16