反射投影 cvCalcBackProject

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
#include "function.h"
CvHistogram* histogram2(IplImage* src,int HSize) //返回归一化的histogram
{
IplImage* SrcH=cvCreateImage(cvGetSize(src),8,1);
//IplImage* SrcS=cvCreateImage(cvGetSize(src),8,1);
//分割HSV
cvSplit(src,SrcH,NULL,NULL,NULL);
//创建histogram
CvHistogram* hist;
int dims=1;
int size[]={HSize};
float RangeH[]={0,180};
//float RangeS[]={0,360};
float* ranges[]={RangeH};
hist=cvCreateHist(dims,size,CV_HIST_ARRAY,ranges);
//计算histogram
IplImage* image[]={SrcH};
cvCalcHist(image,hist);
return hist;
}
int BackProjection(int argc,char** argv) //projection:投射
{
IplImage* temp=cvLoadImage("e:\\picture\\333.jpg");
CvHistogram* hist=histogram2(temp,30);
IplImage* src=cvLoadImage("e:\\picture\\3.jpg");
IplImage* ImageH=cvCreateImage(cvGetSize(src),8,1);
IplImage* ImageS=cvCreateImage(cvGetSize(src),8,1);
IplImage* SrcHSV=cvCreateImage(cvGetSize(src),8,3);
cvCvtColor(src,SrcHSV,CV_BGR2HSV);
cvSplit(SrcHSV,ImageH,NULL,NULL,NULL);
//IplImage* image[]={ImageH};
//IplImage* BackProjectResult=cvCreateImage(cvGetSize(src),8,1);
IplImage* BackProjectResult=cvCreateImage(cvGetSize(src),8,1); //结果的类型要和输入图像具有同样类型,并且hist注意不要归一化,否则所有的值会被四舍五入为0
cvCalcBackProject(&ImageH,BackProjectResult,hist);
double max=0;
double min=0;
cvMinMaxLoc(BackProjectResult,&min,&max);
std::cout<<"max:"<<max<<"min:"<<min<<std::endl;
cvNamedWindow("src");
cvNamedWindow("temp");
cvNamedWindow("BackProjectResult");
cvShowImage("src",src);
cvShowImage("temp",temp);
cvShowImage("BackProjectResult",BackProjectResult);
cvWaitKey(0);
return 0;
}


你可能感兴趣的:(opencv)