Point Cloud Library (PCL)  1.9.1-dev
face_detector.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * @author: Koen Buys
35  */
36 
37 #pragma once
38 
39 #include <pcl/pcl_exports.h>
40 #include <pcl/point_types.h>
41 #include <pcl/point_cloud.h>
42 
43 #include <boost/shared_ptr.hpp>
44 #include <string>
45 #include <vector>
46 
47 #include <cuda_runtime_api.h>
48 
49 #include "NCVHaarObjectDetection.hpp"
50 
51 namespace pcl
52 {
53  namespace gpu
54  {
55  namespace people
56  {
58  {
59  public:
60  using Ptr = boost::shared_ptr<FaceDetector>;
61  using ConstPtr = boost::shared_ptr<const FaceDetector>;
62  //using Labels = DeviceArray2D<unsigned char>;
63  //using Depth = DeviceArray2D<unsigned short>;
64  //using Image = DeviceArray2D<pcl::RGB>;
65 
66  /** \brief This is the constructor **/
67  FaceDetector ( int cols, int rows);
68 
69  NCVStatus
70  loadFromXML2(const std::string &filename,
72  std::vector<HaarStage64> &haar_stages,
73  std::vector<HaarClassifierNode128> &haarClassifierNodes,
74  std::vector<HaarFeature64> &haar_features);
75 
76  static NCVStatus
77  loadFromNVBIN(const std::string &filename,
79  std::vector<HaarStage64> &haar_stages,
80  std::vector<HaarClassifierNode128> &haarClassifierNodes,
81  std::vector<HaarFeature64> &haar_features);
82 
83  NCVStatus
84  ncvHaarLoadFromFile_host(const std::string &filename,
86  NCVVector<HaarStage64> &h_haar_stages,
88  NCVVector<HaarFeature64> &h_haar_features);
89 
90  NCVStatus
91  ncvHaarGetClassifierSize(const std::string &filename, Ncv32u &numStages,
92  Ncv32u &numNodes, Ncv32u &numFeatures);
93 
94  NCVStatus
98  NCVVector<HaarStage64> &d_haar_stages,
100  NCVVector<HaarFeature64> &d_haar_features,
101  NCVVector<HaarStage64> &h_haar_stages,
102  INCVMemAllocator &gpu_allocator,
103  INCVMemAllocator &cpu_allocator,
104  cudaDeviceProp &device_properties,
105  Ncv32u width=640,
106  Ncv32u height=480,
107  NcvBool bFilterRects=false,
108  NcvBool bLargestFace=true);
109 
110  int
111  configure (std::string cascade_file_name);
112 
113  /** \brief Process step, this wraps the Nvidia code **/
114  void process (pcl::PointCloud<pcl::RGB>& cloud,
116 
117  /** \brief largest object sets return configuration **/
118  inline void setLargestObject (bool largest_object)
119  {
120  largest_object_ = largest_object;
121  }
122 
123  inline bool getLargestObject () const
124  {
125  return largest_object_;
126  }
127 
128  /** \brief Set the cuda GPU to use **/
129  void setDeviceId (int id);
130 
131  int getCols () const
132  {
133  return cols_;
134  }
135 
136  void setCols (int cols)
137  {
138  cols_ = cols;
139  }
140 
141  int getRows () const
142  {
143  return rows_;
144  }
145 
146  void setRows (int rows)
147  {
148  rows_ = rows;
149  }
150 
151  std::string
153  {
154  return cascade_file_name_;
155  }
156 
157  void
158  setCascadeFileName (std::string cascadeFileName)
159  {
160  cascade_file_name_ = cascadeFileName;
161  }
162 
163  /** \brief Get the cuda GPU device id in use **/
164  int
165  getDeviceId() {return cuda_dev_id_;}
166 
167  private:
168  bool largest_object_; /** \brief only give back largest object **/
169  bool filter_rects_; /** \brief rectangular filter **/
170 
171  int cuda_dev_id_; /** \brief indicates which GPU to use for this **/
172  cudaDeviceProp cuda_dev_prop_;
173 
174  std::string cascade_file_name_;
175 
176  int rows_; // should default to 480
177  int cols_; // should default to 640
178 
179  HaarClassifierCascadeDescriptor haar_clas_casc_descr_;
180  NCVVectorAlloc<HaarStage64>* haar_stages_dev_;
181  NCVVectorAlloc<HaarStage64>* haar_stages_host_;
182  NCVVectorAlloc<HaarClassifierNode128>* haar_nodes_dev_;
183  NCVVectorAlloc<HaarClassifierNode128>* haar_nodes_host_;
184  NCVVectorAlloc<HaarFeature64>* haar_features_dev_;
185  NCVVectorAlloc<HaarFeature64>* haar_features_host_;
186 
187  INCVMemAllocator* gpu_allocator_;
188  INCVMemAllocator* cpu_allocator_;
189 
190  NCVMemStackAllocator* gpu_stack_allocator_;
191  NCVMemStackAllocator* cpu_stack_allocator_;
192 
193  NCVMemStackAllocator* gpu_counter_;
194  NCVMemStackAllocator* cpu_counter_;
195 
196  };
197  }
198  }
199 }
NCVMemStackAllocator.
Definition: NCV.hpp:424
NCVStatus loadFromXML2(const std::string &filename, HaarClassifierCascadeDescriptor &haar, std::vector< HaarStage64 > &haar_stages, std::vector< HaarClassifierNode128 > &haarClassifierNodes, std::vector< HaarFeature64 > &haar_features)
void setLargestObject(bool largest_object)
largest object sets return configuration
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
boost::shared_ptr< const FaceDetector > ConstPtr
Definition: face_detector.h:61
void setCascadeFileName(std::string cascadeFileName)
void process(pcl::PointCloud< pcl::RGB > &cloud, pcl::PointCloud< pcl::Intensity32u > &cloud_out)
Process step, this wraps the Nvidia code.
Classifier cascade descriptor.
std::string getCascadeFileName() const
NCVStatus ncvHaarLoadFromFile_host(const std::string &filename, HaarClassifierCascadeDescriptor &haar, NCVVector< HaarStage64 > &h_haar_stages, NCVVector< HaarClassifierNode128 > &h_haar_nodes, NCVVector< HaarFeature64 > &h_haar_features)
Defines all the PCL implemented PointT point type structures.
NCVStatus ncvHaarGetClassifierSize(const std::string &filename, Ncv32u &numStages, Ncv32u &numNodes, Ncv32u &numFeatures)
INCVMemAllocator (Interface)
Definition: NCV.hpp:402
int getDeviceId()
Get the cuda GPU device id in use.
FaceDetector(int cols, int rows)
This is the constructor.
static NCVStatus loadFromNVBIN(const std::string &filename, HaarClassifierCascadeDescriptor &haar, std::vector< HaarStage64 > &haar_stages, std::vector< HaarClassifierNode128 > &haarClassifierNodes, std::vector< HaarFeature64 > &haar_features)
NCVStatus NCVprocess(pcl::PointCloud< pcl::RGB > &cloud_in, pcl::PointCloud< pcl::Intensity32u > &cloud_out, HaarClassifierCascadeDescriptor &haar, NCVVector< HaarStage64 > &d_haar_stages, NCVVector< HaarClassifierNode128 > &d_haar_nodes, NCVVector< HaarFeature64 > &d_haar_features, NCVVector< HaarStage64 > &h_haar_stages, INCVMemAllocator &gpu_allocator, INCVMemAllocator &cpu_allocator, cudaDeviceProp &device_properties, Ncv32u width=640, Ncv32u height=480, NcvBool bFilterRects=false, NcvBool bLargestFace=true)
int configure(std::string cascade_file_name)
boost::shared_ptr< FaceDetector > Ptr
Definition: face_detector.h:60
void setDeviceId(int id)
Set the cuda GPU to use.