test_people_groundBasedPeopleDetectionApp.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Point Cloud Library (PCL) - www.pointclouds.org
00005  * Copyright (c) 2013-, Open Perception, Inc.
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * * Redistributions of source code must retain the above copyright
00014  * notice, this list of conditions and the following disclaimer.
00015  * * Redistributions in binary form must reproduce the above
00016  * copyright notice, this list of conditions and the following
00017  * disclaimer in the documentation and/or other materials provided
00018  * with the distribution.
00019  * * Neither the name of the copyright holder(s) nor the names of its
00020  * contributors may be used to endorse or promote products derived
00021  * from this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  * POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * main_ground_based_people_detection_app.cpp
00037  * Created on: Nov 30, 2012
00038  * Author: Matteo Munaro
00039  *
00040  * Test file for testing people detection on a point cloud.
00041  * As a first step, the ground is manually initialized, then people detection is performed with the GroundBasedPeopleDetectionApp class,
00042  * which implements the people detection algorithm described here:
00043  * M. Munaro, F. Basso and E. Menegatti,
00044  * Tracking people within groups with RGB-D data,
00045  * In Proceedings of the International Conference on Intelligent Robots and Systems (IROS) 2012, Vilamoura (Portugal), 2012.
00046  */
00047 
00048 #include <gtest/gtest.h>
00049 #include <pcl/io/pcd_io.h>
00050 #include <pcl/point_types.h>
00051 #include <pcl/visualization/pcl_visualizer.h>
00052 #include <pcl/sample_consensus/sac_model_plane.h>
00053 #include <pcl/people/ground_based_people_detection_app.h>
00054 
00055 typedef pcl::PointXYZRGB PointT;
00056 typedef pcl::PointCloud<PointT> PointCloudT;
00057 
00058 enum { COLS = 640, ROWS = 480 };
00059 PointCloudT::Ptr cloud;
00060 pcl::people::PersonClassifier<pcl::RGB> person_classifier;
00061 std::string svm_filename;
00062 float min_confidence;
00063 float min_height;
00064 float max_height;
00065 float voxel_size;
00066 Eigen::Matrix3f rgb_intrinsics_matrix;
00067 Eigen::VectorXf ground_coeffs;
00068 
00069 TEST (PCL, PersonClassifier)
00070 {
00071   // Create classifier for people detection:
00072   EXPECT_TRUE (person_classifier.loadSVMFromFile(svm_filename)); // load trained SVM
00073 }
00074 
00075 TEST (PCL, GroundBasedPeopleDetectionApp)
00076 {
00077   // People detection app initialization:
00078   pcl::people::GroundBasedPeopleDetectionApp<PointT> people_detector;    // people detection object
00079   people_detector.setVoxelSize(voxel_size);                        // set the voxel size
00080   people_detector.setIntrinsics(rgb_intrinsics_matrix);            // set RGB camera intrinsic parameters
00081   people_detector.setClassifier(person_classifier);                // set person classifier
00082   people_detector.setHeightLimits(min_height, max_height);         // set person classifier
00083 
00084   // Perform people detection on the new cloud:
00085   std::vector<pcl::people::PersonCluster<PointT> > clusters;   // vector containing persons clusters
00086   people_detector.setInputCloud(cloud);
00087   people_detector.setGround(ground_coeffs);                    // set floor coefficients
00088   EXPECT_TRUE (people_detector.compute(clusters));             // perform people detection
00089 
00090   unsigned int k = 0;
00091   for(std::vector<pcl::people::PersonCluster<PointT> >::iterator it = clusters.begin(); it != clusters.end(); ++it)
00092   {
00093     if(it->getPersonConfidence() > min_confidence)             // draw only people with confidence above a threshold
00094       k++;
00095   }
00096   EXPECT_EQ (k, 5);             // verify number of people found (should be five)
00097 }
00098 
00099 int main (int argc, char** argv)
00100 {
00101   if (argc < 2)
00102   {
00103     cerr << "No svm filename provided. Please download `trainedLinearSVMForPeopleDetectionWithHOG.yaml` and pass its path to the test." << endl;
00104     return (-1);
00105   }
00106         
00107   if (argc < 3)
00108   {
00109     cerr << "No test file given. Please download 'five_people.pcd` and pass its path to the test." << endl;
00110     return (-1);
00111   }
00112 
00113   cloud = PointCloudT::Ptr (new PointCloudT);
00114   if (pcl::io::loadPCDFile (argv[2], *cloud) < 0)
00115   {
00116     cerr << "Failed to read test file. Please download `five_people.pcd` and pass its path to the test." << endl;
00117     return (-1);
00118   }     
00119         
00120   // Algorithm parameters:
00121   svm_filename = argv[1];
00122   min_confidence = -1.5;
00123   min_height = 1.3;
00124   max_height = 2.3;
00125   voxel_size = 0.06;
00126 
00127   rgb_intrinsics_matrix << 525, 0.0, 319.5, 0.0, 525, 239.5, 0.0, 0.0, 1.0; // Kinect RGB camera intrinsics
00128   ground_coeffs.resize(4);
00129   ground_coeffs << -0.0103586, 0.997011, 0.0765573, -1.26614;                   // set ground coefficients
00130 
00131   testing::InitGoogleTest (&argc, argv);
00132   return (RUN_ALL_TESTS ());
00133 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:35:24