C++ 如何计算OpenCV C+中按列聚合的亮度直方图+;

C++ 如何计算OpenCV C+中按列聚合的亮度直方图+;,c++,opencv,histogram,ocr,C++,Opencv,Histogram,Ocr,我想分割汽车牌照,以获得单独的字符。 我找到了一些文章,其中使用亮度直方图(据我所知,是所有非零像素的总和)进行分割 如何计算这样的直方图?我真的非常感谢你的帮助 std::vector<int> computeColumnHistogram(const cv::Mat& in) { std::vector<int> histogram(in.cols,0); //Create a zeroed histogram of the necessary siz

我想分割汽车牌照,以获得单独的字符。 我找到了一些文章,其中使用亮度直方图(据我所知,是所有非零像素的总和)进行分割

如何计算这样的直方图?我真的非常感谢你的帮助

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;

}


out
是一个
cv::Mat
,它将有一行。

这是一个简单的(图像到x或y轴的投影)@berak当使用cv\u REDUCE\u SUM?空Mat时,您必须通过哪种输出数组<代码>Mat结果;减少(输入,结果,1,CV_减少_总和,CV_32S)(如果您的行数超过255行,则输出类型应大于CV_8U)@berak谢谢!我猜,加上sum,两行就足够溢出了!如果使用CV_16U,则限制为255行。要按列求和,我认为应该使用“0”,而不是“1”。^^oh,ofc。你说得对。我只是在数我脑袋里的像素,不是它们的总和。非常感谢!这就是我需要的。
cv::reduce(in, out, 0, CV_REDUCE_AVG);
cv::reduce(in, out, 0, CV_REDUCE_SUM, CV_32S);