opencv 绘制H-S直方图
来源:互联网 发布:编程机器人2在线 编辑:程序博客网 时间:2024/05/17 06:02
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main ()
{
Mat srcimg=imread("test.jpg");
Mat Hsvimg;
cvtColor(srcimg,Hsvimg,COLOR_BGR2HSV);
int huebinnum=30;//色调量化
int saturationbinnum=32; //饱和度量化
int histsize[]={huebinnum,saturationbinnum};
float hueRange[]={0,180};//色调的变化范围
float saturationRange[]={0,256};//饱和度的变化范围
const float *ranges[]={hueRange,saturationRange};
MatND dstHist; //MatND 储存直方图的一种数据结构
int channels[]={0,1};//计算第0,1通道的直方图
calcHist(&Hsvimg,1,channels,Mat(),dstHist,2,histsize,ranges,true,false);
//进行直方图计算
//为绘制直方图准备参数
double maxVaule=0;
minMaxLoc(dstHist,0,&maxVaule,0,0);//查找dstHist全局最大最小值后存入maxVaule
int scale=10;
Mat histImg=Mat::zeros(saturationbinnum*scale,huebinnum*10,CV_8UC3);
for(int hue=0;hue<huebinnum;hue++)
for(int saturation=0;saturation<saturationbinnum;saturation++)
{
float binValue = dstHist.at<float>(hue,saturation);//直方图直条的值
int intensity=cvRound(binValue*255/maxVaule); //强度
rectangle(histImg,Point(hue*scale,saturation*scale),Point((hue+1)*scale-1,(saturation+1)*scale-1),Scalar::all(intensity),CV_FILLED);
}
cvtColor(histImg,histImg,COLOR_HSV2BGR);
imshow("hist",histImg);
waitKey(0);
return 0;
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main ()
{
Mat srcimg=imread("test.jpg");
Mat Hsvimg;
cvtColor(srcimg,Hsvimg,COLOR_BGR2HSV);
int huebinnum=30;//色调量化
int saturationbinnum=32; //饱和度量化
int histsize[]={huebinnum,saturationbinnum};
float hueRange[]={0,180};//色调的变化范围
float saturationRange[]={0,256};//饱和度的变化范围
const float *ranges[]={hueRange,saturationRange};
MatND dstHist; //MatND 储存直方图的一种数据结构
int channels[]={0,1};//计算第0,1通道的直方图
calcHist(&Hsvimg,1,channels,Mat(),dstHist,2,histsize,ranges,true,false);
//进行直方图计算
//为绘制直方图准备参数
double maxVaule=0;
minMaxLoc(dstHist,0,&maxVaule,0,0);//查找dstHist全局最大最小值后存入maxVaule
int scale=10;
Mat histImg=Mat::zeros(saturationbinnum*scale,huebinnum*10,CV_8UC3);
for(int hue=0;hue<huebinnum;hue++)
for(int saturation=0;saturation<saturationbinnum;saturation++)
{
float binValue = dstHist.at<float>(hue,saturation);//直方图直条的值
int intensity=cvRound(binValue*255/maxVaule); //强度
rectangle(histImg,Point(hue*scale,saturation*scale),Point((hue+1)*scale-1,(saturation+1)*scale-1),Scalar::all(intensity),CV_FILLED);
}
cvtColor(histImg,histImg,COLOR_HSV2BGR);
imshow("hist",histImg);
waitKey(0);
return 0;
}
阅读全文
1 0
- opencv 绘制H-S直方图
- opencv 2.3.1 绘制H-S直方图
- H-S直方图,opencv
- OpenCV学习---绘制直方图(一维、H-S、RGB)
- opencv3 绘制二维直方图-H-S直方图
- 利用OpenCV的calcHist绘制灰度直方图、H-S直方图、BGR直方图和自定义直方图的源码及说明
- OpenCV环境下计算并绘制HSV空间的H-S的二维联合直方图
- 【拜小白opencv】45-二维H-S直方图绘制----calcHist()函数、minMaxLoc()函数
- OpenCV--绘制直方图&直方图均衡
- opencv绘制灰度直方图
- opencv绘制灰度直方图
- 【OpenCV】绘制直方图
- opencv:绘制直方图
- opencv 绘制图像直方图
- 【OpenCV】绘制直方图
- opencv 绘制灰度直方图
- opencv 图像直方图绘制
- opencv直方图均衡化并绘制直方图
- 如何在页面正确展示表中存储的html
- 合格的字符串
- python 抽取数据
- js无缝滚动
- JDK动态代理为什么必须用接口
- opencv 绘制H-S直方图
- git merge 和 git rebase 小结
- Nifi读取Hive中数据然后再写入新Hive数据库表操作
- 倒计时
- android插件式换肤和应用内换肤
- 解决html的textarea表单里x变为emoji表情问题
- Android中同步与异步
- 史上最全最常用的正则表达式
- ITEXT PDF文件的拆分与合并