Histogram land-based moving distance cvCalcEMD2 based on BGR

Source: Internet
Author: User

and the relative ratio of the land-based moving distance on HSV, this is a three-dimensional histogram

Program:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/45/D2/wKiom1PsHTDzNBGWAAD5S93HnKc168.jpg "title=" Clipboard1.png "alt=" Wkiom1pshtdznbgwaad5s93hnkc168.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/45/D3/wKioL1PsHl2zMXFdAAD-4zaH0xw167.jpg "title=" Clipboard2.png "alt=" Wkiol1pshl2zmxfdaad-4zah0xw167.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/45/D3/wKioL1PsHm2wNc02AAEVYPg_nnQ641.jpg "title=" Clipboard3.png "alt=" Wkiol1pshm2wnc02aaevypg_nnq641.jpg "/>

Conclusion:

Compared to the base distance based on HSV, the effect is not as good as HSV

Code:

#include   "Cv.h" #include   "cxcore.h" #include   "highgui.h" #include  <iostream>cvhistogram * histogram (iplimage* src,int bsize,int gsize,int rsize)  //return to normalized histogram{ Iplimage* srcb=cvcreateimage (Cvgetsize (SRC), 8,1); Iplimage* srcg=cvcreateimage (CvGetSize (SRC), 8,1); Plimage* srcr=cvcreateimage (Cvgetsize (SRC), 8, 1);//Split Hsvcvsplit (Src,srcb,srcg,srcr,null);// Create histogramcvhistogram* hist;int dims=3;int size[]={bsize,gsize,rsize};float rangeb[]={ 0,255};float rangeg[]={0,255};float ranger[]={0,255};float* ranges[]={rangeb,rangeg,ranger}; Hist=cvcreatehist (dims,size,cv_hist_array,ranges);//Calculation histogramiplimage* image[]={srcb,srcg,srcr}; Cvcalchist (image,hist);//Normalization of histogramcvnormalizehist (hist,1.0); return hist;} Cvmat* createsignature (cvhistogram* hist,int bsize,int gsize,int rsize)   // Get signature{int rows=bsize*gsize*rsize; by histogram Cvmat* mat=cvcReatemat (ROWS,4,CV_32FC1);  //The first column results, the second column is the row number of the result in histogram, and the third column is the number for (int z=0;z<bsize;z++) {for (int  y=0;y<gsize;y++) {for (int x=0;x<rsize;x++) {float data=cvqueryhistvalue_3d (hist,z,y,x);// STD::COUT&LT;&LT;DATA&LT;&LT;STD::ENDL;CVSET2D (mat,z* (gsize*rsize) +y*rsize+x,0,cvscalar (data)) CvSet2D (mat,z* ( gsize*rsize) +y*rsize+x,1,cvscalar (z)), cvset2d (mat,z* (gsize*rsize) +y*rsize+x,2,cvscalar (y)), CvSet2D (mat,z* ( Gsize*rsize) +y*rsize+x,3,cvscalar (x));}} Return mat;} INT&NBSP;CALCEMD2BASEONBGR (INT&NBSP;ARGC,CHAR**&NBSP;ARGV) {iplimage* src1=cvloadimage ("e:\\picture\\4.jpg Iplimage* src2=cvloadimage ("e:\\picture\\11.jpg"); int bsize=20;  //theoretically, CvCalcEMD2 can calculate the maximum histogram signature line number is 15440, and 20*20*20<15440, so can not be used 30,30,30int gsize=20;int rsize=20; Cvhistogram* hist1=histogram (src1,bsize,gsize,rsize); Cvhistogram* hist2=histogram (src2,bsize,gsize,rsize); Cvmat* mat1=createsignature (hist1,bsize,gsize,rsize); Cvmat* mat2=createsignature(hist2,bsize,gsize,rsize);//float max=0; //   float min=0;//cvgetminmaxhistvalue (Hist2,&min,&max);//std::cout<< "Hist1" <<min<< " " <<max<<std::endl;// Double max=0;//double min=0;//cvminmaxloc (Mat2,&min,&max);//std::cout<< "MAT1" << min<< " " <<max<<std::endl;//calculates land-based moving distance FLOAT&NBSP;EMD2RESULT=CVCALCEMD2 (mat1,mat2,cv_dist_ L2);std::cout<< "0 is best" <<std::endl;std::cout<< "Emd2result:" <<emd2result <<std::endl;cvnamedwindow ("Src1"); Cvnamedwindow ("Src2"); Cvshowimage ("Src1", Src1); Cvshowimage ("Src2", Src2 ); Cvwaitkey (0); Cvdestroywindow ("Src1"); Cvdestroywindow ("Src2"); Cvreleaseimage (&AMP;SRC1); Cvreleaseimage (& SRC2); return 0;}


This article is from the "FLYCLC" blog, make sure to keep this source http://flyclc.blog.51cto.com/1385758/1539770

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.