【问题标题】:In C, given an image containing numbers, how do I extract each individual number into a separate image? [closed]在 C 中,给定包含数字的图像,如何将每个单独的数字提取到单独的图像中? [关闭]
【发布时间】:2014-10-12 00:40:34
【问题描述】:

举个例子。假设图像包含黑色的数字 1 和 2。背景是白色的。我想得到两个新文件,其中一个只包含数字 1,另一个只包含数字 2。我一直在 OpenCv 中使用 Sift,但作为图像处理的新手,我需要一些指导。任何帮助是极大的赞赏。

【问题讨论】:

  • 图片的属性是什么?他们可能会有所帮助。例如,如果图像已经水平旋转,并且 1 和 2 位并排、对齐并且一般来说没有损坏,那么简单地检测两个数字之间的间隙并通过扫描白色像素列。我们这样做是为了车牌阅读器。

标签: c opencv image-processing sift


【解决方案1】:
  1. 扫描图像。
  2. 当你找到一个黑色像素时,用白色填充, 生成带有其中一个字符的图像。
  3. 反转生成的图像 并将其添加到原始图像中,从而生成带有 其他角色。

例如(这假设只有 2 个数字,正如您指定的那样)

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;
            }
        }
    }
}

【讨论】:

    【解决方案2】:

    尝试进行连通分量分析。然后你可以根据这些区域划分你的图像。 见here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2016-09-08
      • 2019-12-03
      相关资源
      最近更新 更多