首页 > 代码库 > 基于块的反射投影
基于块的反射投影
#include "cv.h" #include "cxcore.h" #include "highgui.h" #include <iostream> #include "function.h" CvHistogram* histogram2(IplImage* src,int HSize,int SSize) //返回归一化的histogram { IplImage* SrcH=cvCreateImage(cvGetSize(src),8,1); IplImage* SrcS=cvCreateImage(cvGetSize(src),8,1); //分割HSV cvSplit(src,SrcH,SrcS,NULL,NULL); //创建histogram CvHistogram* hist; int dims=2; int size[]={HSize,SSize}; float RangeH[]={0,180}; float RangeS[]={0,360}; float* ranges[]={RangeH,RangeS}; hist=cvCreateHist(dims,size,CV_HIST_ARRAY,ranges); //计算histogram IplImage* image[]={SrcH,SrcS}; cvCalcHist(image,hist); return hist; } int BackProjection(int argc,char** argv) //projection:投射 { IplImage* temp=cvLoadImage("e:\\picture\\333.jpg"); CvHistogram* hist=histogram(temp,30,32); 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,ImageS,NULL,NULL); IplImage* image[]={ImageH,ImageS}; //IplImage* BackProjectResult=cvCreateImage(cvGetSize(src),8,1); IplImage* BackProjectResult=cvCreateImage(cvSize(src->width-temp->width+1,src->height-temp->height+1),IPL_DEPTH_32F,1); //结果的类型要和输入图像具有同样类型,并且hist注意不要归一化,否则所有的值会被四舍五入为0 cvCalcBackProjectPatch(image,BackProjectResult,cvSize(temp->width,temp->height),hist,CV_COMP_CORREL,1); 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/1539759
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。