0

As an example. Suppose an image contains the number 1 and 2 in black. The background is white. I want to end up with two new files where one contains just the number 1 and the other contains just the number 2. I have been playing around with Sift in OpenCv, but being a complete novice at image processing, I need some guidance. Any help is greatly appreciated.

  • What are the properties of the image? They may be helpful. For instance if the image is already rotated level and the 1 and 2 digits are side-by-side, aligned and generally speaking undamaged, it may be trivial to simply detect the gap between the two digits and cut in-between by scanning for a column of white pixels. We did this for a license plate reader. – Iwillnotexist Idonotexist Aug 19 '14 at 03:15

2 Answers2

1

Try to do connected components analysis. Then you can divide your image based on these areas. See here

Community
  • 1
  • 1
Samer
  • 1,923
  • 3
  • 34
  • 54
0
  1. Scan the image.
  2. When you find a black pixel, flood fill with white, resulting in an image with one of the characters.
  3. Invert the resulting image and add it to the original image, resulting in an image with the other character.

E.g. (this assumes there are only 2 numbers, as you specified)

void save_numbers(cv::Mat image) // Assume image type is CV_8UC1
{
    for(int i = 0; i < image.rows; ++i)
    {
        uchar *row = image.ptr<uchar>(i);

        for(int j = 0; j < image.cols; ++j)
        {
            if(row[j] == 0)  // found a black pixel
            {
                cv::Mat number1 = image.clone();
                cv::floodFill(number1, cv::Point(j, i), 255);
                cv::Mat number2 = 255 - number1 + image;
                cv::imwrite("number1.png", number1);
                cv::imwrite("number2.png", number2);
                return;
            }
        }
    }
}
Bull
  • 11,771
  • 9
  • 42
  • 53