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.
Asked
Active
Viewed 187 times
0
-
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 Answers
0
- Scan the image.
- When you find a black pixel, flood fill with white, resulting in an image with one of the characters.
- 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