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 Labels = DeviceArray2D<unsigned char>;
62  //using Depth = DeviceArray2D<unsigned short>;
63  //using Image = DeviceArray2D<pcl::RGB>;
64 
65  /** \brief This is the constructor **/
66  FaceDetector ( int cols, int rows);
67 
68  NCVStatus
69  loadFromXML2(const std::string &filename,
71  std::vector<HaarStage64> &haar_stages,
72  std::vector<HaarClassifierNode128> &haarClassifierNodes,
73  std::vector<HaarFeature64> &haar_features);
74 
75  static NCVStatus
76  loadFromNVBIN(const std::string &filename,
78  std::vector<HaarStage64> &haar_stages,
79  std::vector<HaarClassifierNode128> &haarClassifierNodes,
80  std::vector<HaarFeature64> &haar_features);
81 
82  NCVStatus
83  ncvHaarLoadFromFile_host(const std::string &filename,
85  NCVVector<HaarStage64> &h_haar_stages,
87  NCVVector<HaarFeature64> &h_haar_features);
88 
89  NCVStatus
90  ncvHaarGetClassifierSize(const std::string &filename, Ncv32u &numStages,
91  Ncv32u &numNodes, Ncv32u &numFeatures);
92 
93  NCVStatus
97  NCVVector<HaarStage64> &d_haar_stages,
99  NCVVector<HaarFeature64> &d_haar_features,
100  NCVVector<HaarStage64> &h_haar_stages,
101  INCVMemAllocator &gpu_allocator,
102  INCVMemAllocator &cpu_allocator,
103  cudaDeviceProp &device_properties,
104  Ncv32u width=640,
105  Ncv32u height=480,
106  NcvBool bFilterRects=false,
107  NcvBool bLargestFace=true);
108 
109  int
110  configure (std::string cascade_file_name);
111 
112  /** \brief Process step, this wraps the Nvidia code **/
113  void process (pcl::PointCloud<pcl::RGB>& cloud,
115 
116  /** \brief largest object sets return configuration **/
117  inline void setLargestObject (bool largest_object)
118  {
119  largest_object_ = largest_object;
120  }
121 
122  inline bool getLargestObject () const
123  {
124  return largest_object_;
125  }
126 
127  /** \brief Set the cuda GPU to use **/
128  void setDeviceId (int id);
129 
130  int getCols () const
131  {
132  return cols_;
133  }
134 
135  void setCols (int cols)
136  {
137  cols_ = cols;
138  }
139 
140  int getRows () const
141  {
142  return rows_;
143  }
144 
145  void setRows (int rows)
146  {
147  rows_ = rows;
148  }
149 
150  std::string
152  {
153  return cascade_file_name_;
154  }
155 
156  void
157  setCascadeFileName (std::string cascadeFileName)
158  {
159  cascade_file_name_ = cascadeFileName;
160  }
161 
162  /** \brief Get the cuda GPU device id in use **/
163  int
164  getDeviceId() {return cuda_dev_id_;}
165 
166  private:
167  bool largest_object_; /** \brief only give back largest object **/
168  bool filter_rects_; /** \brief rectangular filter **/
169 
170  int cuda_dev_id_; /** \brief indicates which GPU to use for this **/
171  cudaDeviceProp cuda_dev_prop_;
172 
173  std::string cascade_file_name_;
174 
175  int rows_; // should default to 480
176  int cols_; // should default to 640
177 
178  HaarClassifierCascadeDescriptor haar_clas_casc_descr_;
179  NCVVectorAlloc<HaarStage64>* haar_stages_dev_;
180  NCVVectorAlloc<HaarStage64>* haar_stages_host_;
181  NCVVectorAlloc<HaarClassifierNode128>* haar_nodes_dev_;
182  NCVVectorAlloc<HaarClassifierNode128>* haar_nodes_host_;
183  NCVVectorAlloc<HaarFeature64>* haar_features_dev_;
184  NCVVectorAlloc<HaarFeature64>* haar_features_host_;
185 
186  INCVMemAllocator* gpu_allocator_;
187  INCVMemAllocator* cpu_allocator_;
188 
189  NCVMemStackAllocator* gpu_stack_allocator_;
190  NCVMemStackAllocator* cpu_stack_allocator_;
191 
192  NCVMemStackAllocator* gpu_counter_;
193  NCVMemStackAllocator* cpu_counter_;
194 
195  };
196  }
197  }
198 }
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
void setCascadeFileName(std::string cascadeFileName)
std::string getCascadeFileName() const
void process(pcl::PointCloud< pcl::RGB > &cloud, pcl::PointCloud< pcl::Intensity32u > &cloud_out)
Process step, this wraps the Nvidia code.
Classifier cascade descriptor.
NCVStatus ncvHaarLoadFromFile_host(const std::string &filename, HaarClassifierCascadeDescriptor &haar, NCVVector< HaarStage64 > &h_haar_stages, NCVVector< HaarClassifierNode128 > &h_haar_nodes, NCVVector< HaarFeature64 > &h_haar_features)
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)
PointCloud represents the base class in PCL for storing collections of 3D points. ...
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.