给定三幅在书中讨论的不同光照条件下的手图像,利用cvCalcHist()来获得室内拍照的手的色肤直方图
分别给定2维、8维、16维、32维、256维进行运算
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
#define cvQueryHistValue_1D( hist, idx0 ) cvGetReal1D( (hist)->bins, (idx0) )
#define cvQueryHistValue_2D( hist, idx0 , idx1 ) cvGetReal2D( (hist)->bins, (idx0) , (idx1))
#define binNum 2 // 每一位幅bin的大小
/*画直方图*/
void DisplayHistogram(CvHistogram * hist , char * windName)
{
if(!hist || !windName)
{
return;
}
int scale = 100; //缩放比例
int h_bins = hist->mat.dim[0].size;
int s_bins = hist->mat.dim[1].size;
IplImage * histImg = cvCreateImage(cvSize(h_bins * scale , s_bins * scale), 8, 3);
cvSetZero(histImg);
//显示直方图
float max_value = 0;
float bin_value = 0;
int intensity = 0;
cvGetMinMaxHistValue(hist, 0, &max_value,0,0);
for(int i = 0;i<h_bins;i++)
{
for(int j = 0;j<s_bins;j++)
{
bin_value = cvQueryHistValue_2D( hist, i, j);
intensity = cvRound(bin_value * 255 / max_value);
cvRectangle(histImg, cvPoint(i*scale, j*scale), cvPoint((i+1)*scale-1, (j+1)*scale-1),
CV_RGB(intensity, intensity, intensity),CV_FILLED);
}
}
cvNamedWindow(windName);
cvShowImage(windName, histImg);
}
int main(int argc, const char * argv[]) {
/*1、加载图片*/
const char filename1[] = "/Users/linwang/Downloads/hand1.jpg";
const char filename2[] = "/U