<span style="font-size:14px;">#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv\cxcore.h>
IplImage* DrawHistogram(CvHistogram* hist, float scaleX = 1, float scaleY = 1){
float histMax = 0;
cvGetMinMaxHistValue(hist, 0, &histMax, 0, 0); //获取直方图的最大值
IplImage* imageHist = cvCreateImage(cvSize(256*scaleX, 64*scaleY), 8, 1);
cvZero(imageHist);
for(int i = 0; i < 255; ++i){
//查询直方图每个单位的x值对应的y值
float histValue = cvQueryHistValue_1D(hist, i);
float nextValue = cvQueryHistValue_1D(hist, i+1);
CvPoint pt1 = cvPoint(i* scaleX, 64*scaleY);
CvPoint pt2 = cvPoint((i+1)*scaleX, 64*scaleY);
CvPoint pt3 = cvPoint((i+1)*scaleX, 64*scaleY - (nextValue/histMax)*64*scaleY);
CvPoint pt4 = cvPoint(i*scaleX, 64*scaleY - (histValue/histMax)*64*scaleY);
int numPts
OpenCV:绘制图像的BGR三通道直方图
最新推荐文章于 2024-01-22 03:13:31 发布
本文介绍了如何利用OpenCV库在Python中分别绘制BGR三通道的图像直方图。通过这一过程,读者可以理解每个通道颜色在图像中的分布情况。
摘要由CSDN通过智能技术生成