OPENCV implementation of canopy algorithm

Source: Internet
Author: User

#include"stdafx.h"using namespaceCV;intMainintargcChar**argv) {Mat img=imread ("d:/pic/lena.jpg"); Imshow ("src", IMG); Cv_assert (!img.empty ()); Vector<Mat>planes;    Split (Img,planes); intTotal=img.total (); Mat p (Total,3, Cv_32f,scalar::all (0)); inti;  for(i=0; i<total;i++) {p.at<float> (I,0) =planes[0].data[i]; p.at<float> (I,1) =planes[1].data[i]; p.at<float> (I,2) =planes[2].data[i]; } rng rng (12345); intnum=0;//Number of canopy    Doublet1=200.0, t2=100.0;//Two distance thresholdvector<mat> canopy (total);//Canopy Matrix Group     while(!P.empty ()) {                intR=p.rows;//number of rows for the remaining dataMat temp; intK=rng.uniform (0, R);//randomly selected one of the remaining data as the Canopy centercout<<"The rest of number of rows:"<<r<<", Random:"<<k<<Endl;  for(i=0; i<r;i++)        {            DoubleD=norm (P.row (k), P.row (i));//calculate the distance between the selected point and other points            if(d<=t1) Canopy[num].push_back (P.row (i)); //Place all points that are less than T1 into a new canopy            if(d>T2) Temp.push_back (P.row (i)); //Update Data} temp.copyto (P); Num++; } cout<<"The total number of canopy:"<<num<<endl;//number of final categories     for(i=0; i<num;i++) cout<<" the number of"<<i+1<<"class:"<<canopy[i].total () <<Endl; Waitkey (0); return 0;}

OPENCV implementation of canopy algorithm

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.