opencv_19_图像直方图

1)void histogram_demo(Mat& image);

2)void ColorInvert::histogram_demo(Mat& image) {

std::vector<Mat>bgr_plane;

split(image, bgr_plane);

const int channels1 = { 0 };

const int bins1 = { 256 };

float hranges2 = { 0,255 };

const float* ranges1 = { hranges };

Mat b_hist;

Mat g_hist;

Mat r_hist;

calcHist(&bgr_plane0, 1, 0, Mat(), b_hist, 1, bins, ranges);

calcHist(&bgr_plane1, 1, 0, Mat(), g_hist, 1, bins, ranges);

calcHist(&bgr_plane2, 1, 0, Mat(), r_hist, 1, bins, ranges);

int hist_w = 512;

int hist_h = 400;

int bin_w = cvRound((double)hist_w / bins0);

Mat histImage = Mat::zeros(hist_h, hist_w, CV_8UC3);

normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

for (int i = 1; i < bins0; i++)

{

line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w * (i),hist_h-cvRound(b_hist.at<float>(i))),Scalar(255,0,0),2,8,0);

line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w * (i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0);

line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w * (i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0);

}

namedWindow("Histogram Demo", WINDOW_AUTOSIZE);

imshow("Histogram Demo", histImage);

}

直方图:

相关推荐
找方案几秒前
北京砸1亿支持智能体:Agent创业迎来黄金窗口期
大数据·人工智能·microsoft
Revolution619 分钟前
多个 Agent 同时工作时,主 Agent 怎样接收队友结果
人工智能·llm·claude
不加辣椒16 分钟前
第8章:工具调用与多模态上下文集成
人工智能
葡萄城技术团队17 分钟前
三大适配场景:释放AI Coding真实落地价值(四)
人工智能
MomentYY23 分钟前
RAG 混合检索:关键词 + 语义
人工智能·agent·ai编程
Black蜡笔小新24 分钟前
EasyAIS+国标GB28181视频监控平台EasyCVR强强联动,全域视频AI识别能力落地!
大数据·人工智能·音视频
Microvision维视智造25 分钟前
智能工厂等级自检表:梯度培育,你的工厂在第几级?
人工智能·计算机视觉·视觉检测·机器视觉
时光不负努力30 分钟前
skill 定义 + 多个skill 协作
人工智能·openai
武子康1 小时前
MCP 2026-07-28 无状态核心之后:身份、任务、幂等与审计状态到底放在哪里?
人工智能·llm·mcp
瓦学妹1 小时前
X(Twitter)新号如何防封?2026 养号与防限流全攻略
大数据·网络·人工智能·新媒体运营·twitter