首页 > 代码库 > 反射投影 cvCalcBackProject
反射投影 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=http://www.mamicode.com/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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。