00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00027 #include "peddetect.h" 00028 00029 int main (int argc, char **argv) 00030 { 00031 00032 /* STEP 2. Opening the file */ 00033 //1. Declare a structure to keep the data 00034 CvMLData cvml; 00035 //2. Read the file 00036 cvml.read_csv ("/home/pedrobatista/workingcopy/lar3/perception/pedestrians/PedestrianDetect/train_15000_boot3.csv"); 00037 //3. Indicate which column is the response 00038 00039 cvml.set_response_idx (0); 00040 // CvTrainTestSplit cvtts (8000, true); 00041 // cvml.set_train_test_split (&cvtts); 00042 00043 const CvMat* Resp = cvml.get_responses(); 00044 const CvMat* Values = cvml.get_values(); 00045 00046 Mat RespM(Resp, false); 00047 Mat ValM(Values,false); 00048 00049 // RespM.assignTo(RespM, CV_32F ); 00050 // ValM.assignTo(ValM, CV_32F ); 00051 00052 00053 00054 Mat trainData = ValM.colRange(1, 15001); 00055 cout<<trainData.size()<<endl; 00056 // cout<<trainData.at<float>(0,0)<<endl; 00057 00058 // Mat varIdx(1,NRFEATURE,CV_32F); 00059 // 00060 // for (int n=0; n<varIdx.cols;n++) 00061 // varIdx.at<float>(1,n)=n; 00062 // 00063 // Mat sampleIdx(1,trainData.rows,CV_32F); 00064 // 00065 // for (int i=0; i<sampleIdx.cols;i++) 00066 // sampleIdx.at<float>(1,i)=i; 00067 // 00068 // Mat varType(1,trainData.rows,CV_32F); 00069 // 00070 // 00071 // for (int y=0; y<sampleIdx.cols;y++) 00072 // varType.at<float>(1,y)=CV_VAR_CATEGORICAL; 00073 00074 00075 00076 00077 CvBoost boost; 00078 00079 boost.train( trainData, 00080 CV_ROW_SAMPLE, 00081 RespM, 00082 Mat(), 00083 Mat(), 00084 Mat(), 00085 Mat(), 00086 CvBoostParams(CvBoost::REAL,2000, 0.95, 2, false, 0), 00087 false); 00088 00089 00090 // float elements[10]; 00091 // CvSeq * weak = boost.get_weak_predictors(); 00092 // 00093 // CvtSeqToArray(weak,elements,CV_WHOLE_SEQ); 00094 00095 00096 00097 // cout<<weak->total<<endl; 00098 00099 // CvPoint pt0; 00100 00101 // for(int i = 0; i < weak->total; i++) 00102 // { 00103 // pt0 = *CV_GET_SEQ_ELEM( CvPoint, weak, i ); 00104 // cout<<pt0.x<<endl; 00105 // } 00106 00107 00108 00109 boost.save ("./trained_boost_10Kf_2000w_13Ks_m8_M64_boot1.xml", "boost"); 00110 00111 00112 return 0; 00113 00114 }