//快速排序
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <direct.h>
using namespace cv;
using namespace std;
Mat calcGrayHist(Mat img);
int main() {
// 直方图
char *buf;
Mat img = imread("D:\\Users\\4399-5080\\Desktop\\w.png");
//imshow("H", img);
calcGrayHist(img);
//waitKey(0);
};
Mat calcGrayHist(Mat img) {
Mat histogram = Mat::zeros(Size(256, 1), CV_32SC1);
int rows = img.rows;
int cols = img.cols;
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
int index = int(img.at<uchar>(r, c));
histogram.at<int>(0, index) += 1;
}
}
return histogram;
}
C++ 之直方图的计算
于 2022-09-01 15:42:32 首次发布
本文详细介绍了如何使用C++和OpenCV库来计算图像的直方图,探讨了直方图在计算机视觉中的应用,并提供了具体的代码示例,帮助读者理解直方图在图像处理中的重要性。
2518

被折叠的 条评论
为什么被折叠?



