# Include "CV. H "# include" cxcore. H "# include" highgui. H "# include <iostream> # include" function. H "cvhistogram * histogram2 (iplimage * SRC, int hsize) // return the normalized histogram {iplimage * srch = cvcreateimage (cvgetsize (SRC), 8, 1 ); // iplimage * SRCS = cvcreateimage (cvgetsize (SRC), 8, 1); // You can split the CIDR Block (SRC, srch, null). // create histogramcvhistogram * 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); // calculate histogramiplimage * image [] = {srch}; cvcalchist (image, hist); Return hist;} int Backprojection (INT argc, char ** argv) // projection: 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); // iplimage * image [] = {imageh }; // iplimage * backprojectresult = cvcreateimage (cvgetsize (SRC), 8, 1); iplimage * backprojectresult = cvcreateimage (cvgetsize (SRC), 8, 1 ); // The result type must be the same as the input image, and hist must not be normalized. Otherwise, all values are rounded to 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 ;}
This article is from the "flyclc" blog, please be sure to keep this source http://flyclc.blog.51cto.com/1385758/1539757