#include <opencv2/opencv.hpp>
#include <iostream>
#include <cmath>
#include <opencv2\imgproc\types_c.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
Mat getHistograph(const Mat grayImage); // 计算直方图
cv::Mat BGR2GRAY(cv::Mat img) {
//RGB转灰度图像函数1
int width = img.cols;
int height = img.rows;
cv::Mat out = cv::Mat::zeros(height, width, CV_8UC1);//8位无符号灰度图像
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
//RGB分量取不同的权重
out.at<uchar>(y, x) = 0.2126 * img.at<cv::Vec3b>(y, x)[2] \ // Vec3b可以看作是vector<uchar, 3>。
// 简单而言就是一个uchar类型的,长度为3的vector向量。
+ 0.7152 * img.at<cv::Vec3b>(y, x)[1] \
+ 0.0722 * img.at<cv::Vec3b>(y
C++ opencvRGB转灰度图,求灰度图直方图
最新推荐文章于 2024-08-04 02:33:08 发布
这篇博客介绍了如何使用C++和OpenCV库将RGB图像转换为灰度图像,并详细阐述了计算得到的灰度图像的直方图过程。
摘要由CSDN通过智能技术生成