<分区>
为了分割我用于亮度直方图的车牌字符。 为了解决这个问题,我写了这段代码:
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)
如何重复结果?