如何计算OpenCV C ++中按列聚合的亮度直方图 [英] How do I compute the brightness histogram aggregated by column in OpenCV C++
本文介绍了如何计算OpenCV C ++中按列聚合的亮度直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想分割车牌以获得单独的字符。
我发现了一些文章,其中使用亮度直方图进行这种分割(因为我理解 - 所有非零像素的和)。
I want to segment car plate to get separate characters. I found some article, where such segmentation performed using brightness histograms (as i understand - sum of all non-zero pixels).
如何计算这种直方图?我非常感谢任何帮助!
How can i calculate such histogram? I would really appreciate for any help!
推荐答案
std::vector<int> computeColumnHistogram(const cv::Mat& in) {
std::vector<int> histogram(in.cols,0); //Create a zeroed histogram of the necessary size
for (int y = 0; y < in.rows; y++) {
p_row = in.ptr(y); ///Get a pointer to the y-th row of the image
for (int x = 0; x < in.cols; x++)
histogram[x] += p_row[x]; ///Update histogram value for this image column
}
//Normalize if you want (you'll get the average value per column):
// for (int x = 0; x < in.cols; x++)
// histogram[x] /= in.rows;
return histogram;
}
或使用 reduce ,或者呼叫
cv::reduce(in, out, 0, CV_REDUCE_AVG);
或
cv::reduce(in, out, 0, CV_REDUCE_SUM, CV_32S);
out
> cv :: Mat ,它将有一行。
out
is a cv::Mat
, and it will have a single row.
这篇关于如何计算OpenCV C ++中按列聚合的亮度直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文