码迷,mamicode.com
首页 > 其他好文 > 详细

反射投影 cvCalcBackProject

时间:2014-08-14 17:11:29      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:cvcalcbackproject opencv

#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;
}


本文出自 “flyclc” 博客,请务必保留此出处http://flyclc.blog.51cto.com/1385758/1539757

反射投影 cvCalcBackProject,布布扣,bubuko.com

反射投影 cvCalcBackProject

标签:cvcalcbackproject opencv

原文地址:http://flyclc.blog.51cto.com/1385758/1539757

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!