c++ - 车牌在符号上的分割

标签 c++ opencv

<分区>

为了分割我用于亮度直方图的车牌字符。 为了解决这个问题,我写了这段代码:

std::vector<int> computeColumnHistogram(const cv::Mat& img) 
{
    size_t width = img.size().width;
    size_t height = img.size().height;
    auto prow = img.ptr(0);
    std::vector<int> histogram(width,0); //Create a zeroed histogram of the necessary size
    for (int y = 0; y < height; y++) 
    {
        prow = img.ptr(y); // Get a pointer to the y-th row of the image
        for (int x = 0; x < width; x++)
            histogram[x] += prow[x]; // Update histogram value for this image column
    }

    for (int x = 0; x < width; x++)
        histogram[x] /= height;

    int max = *std::max_element(histogram.begin(), histogram.end());

    cv::Mat histo; 
    histo = cv::Mat::zeros(cv::Size(width,max), CV_8U);

    for(int i=0; i< width; ++i)  
    {  
        for(int j=0; j< histogram.at(i); ++j)  
            histo.at<unsigned char>(max-j-1,i) = 255;  
    }  

    imshow("hh", histo);

    return histogram;
}

int main(int argc, char** argv)
{
    cv::Mat img = imread(argv[1], 0);

    imshow("Sourse", img);

    std::vector<int> hist = computeColumnHistogram(img);

    for(auto &e : hist)
        std::cout << e << std::endl;

    waitKey();
    return 0;
}

图像 1 上表示的程序的输出:

Image 1 (http://i.stack.imgur.com/d56Cy.png)

我尝试了很多方法来确定符号的位置,但都无济于事。

我发现一篇文章描述了一种使用局部最大值的类似方法。 Image 2 (http://i.stack.imgur.com/lp1MD.png)

如何重复结果?

最佳答案

我会先尝试对图像进行阈值处理,以获得符号/背景的二进制图像(例如:http://www.ijcset.net/docs/Volumes/volume2issue1/ijcset2012020103.pdf)。阈值处理后,使用中值滤波器就足以去除分割后剩余的类似噪声的像素。

图像经过中值滤波后,只需开始寻找图像中的第一个黑色像素并执行区域生长,以找到对象(符号)最右边的黑色像素。一旦你有了它,从前一个对象的最右边的像素开始重新启动算法(寻找最左边的黑色像素)。这样您将获得每个符号的起始像素和结束像素。

关于c++ - 车牌在符号上的分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30796137/

相关文章:

c++ - 处理无效操作数错误

c++ - 编译器 g++ 无法创建 a.out 文件?

c++ - filter2D 实现的差异

python - 使用 OpenCV Python 从 BGR 转换为 YUYV

opencv - 来自 makePtr 的范围

MVS 2012 上的 C++ Detours 3.0 Express 错误 "identifier not found"

c++ - 在 C++ 中读取返回零

c++ - 同样的程序在 Linux 上比在 Windows 上运行更快——为什么?

c++ - 从图像点构建树/图

python - 在OpenCV中删除图像中的噪声而不会丢失数据