Point Cloud Library (PCL)  1.14.0-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/memory.h>
40 #include <pcl/pcl_exports.h>
41 #include <pcl/point_types.h>
42 #include <pcl/point_cloud.h>
43 
44 
45 #include <string>
46 #include <vector>
47 
48 #include <cuda_runtime_api.h>
49 
50 #include "NCVHaarObjectDetection.hpp"
51 
52 namespace pcl
53 {
54  namespace gpu
55  {
56  namespace people
57  {
59  {
60  public:
61  using Ptr = shared_ptr<FaceDetector>;
62  using ConstPtr = shared_ptr<const FaceDetector>;
63  //using Labels = DeviceArray2D<unsigned char>;
64  //using Depth = DeviceArray2D<unsigned short>;
65  //using Image = DeviceArray2D<pcl::RGB>;
66 
67  /** \brief This is the constructor **/
68  FaceDetector ( int cols, int rows);
69 
70  NCVStatus
71  loadFromXML2(const std::string &filename,
73  std::vector<HaarStage64> &haar_stages,
74  std::vector<HaarClassifierNode128> &haarClassifierNodes,
75  std::vector<HaarFeature64> &haar_features);
76 
77  static NCVStatus
78  loadFromNVBIN(const std::string &filename,
80  std::vector<HaarStage64> &haar_stages,
81  std::vector<HaarClassifierNode128> &haarClassifierNodes,
82  std::vector<HaarFeature64> &haar_features);
83 
84  NCVStatus
85  ncvHaarLoadFromFile_host(const std::string &filename,
87  NCVVector<HaarStage64> &h_haar_stages,
89  NCVVector<HaarFeature64> &h_haar_features);
90 
91  NCVStatus
92  ncvHaarGetClassifierSize(const std::string &filename, Ncv32u &numStages,
93  Ncv32u &numNodes, Ncv32u &numFeatures);
94 
95  NCVStatus
99  NCVVector<HaarStage64> &d_haar_stages,
100  NCVVector<HaarClassifierNode128> &d_haar_nodes,
101  NCVVector<HaarFeature64> &d_haar_features,
102  NCVVector<HaarStage64> &h_haar_stages,
103  INCVMemAllocator &gpu_allocator,
104  INCVMemAllocator &cpu_allocator,
105  cudaDeviceProp &device_properties,
106  Ncv32u width=640,
107  Ncv32u height=480,
108  NcvBool bFilterRects=false,
109  NcvBool bLargestFace=true);
110 
111  int
112  configure (std::string cascade_file_name);
113 
114  /** \brief Process step, this wraps the Nvidia code **/
117 
118  /** \brief largest object sets return configuration **/
119  inline void setLargestObject (bool largest_object)
120  {
121  largest_object_ = largest_object;
122  }
123 
124  inline bool getLargestObject () const
125  {
126  return largest_object_;
127  }
128 
129  /** \brief Set the cuda GPU to use **/
130  void setDeviceId (int id);
131 
132  int getCols () const
133  {
134  return cols_;
135  }
136 
137  void setCols (int cols)
138  {
139  cols_ = cols;
140  }
141 
142  int getRows () const
143  {
144  return rows_;
145  }
146 
147  void setRows (int rows)
148  {
149  rows_ = rows;
150  }
151 
152  std::string
154  {
155  return cascade_file_name_;
156  }
157 
158  void
159  setCascadeFileName (std::string cascadeFileName)
160  {
161  cascade_file_name_ = cascadeFileName;
162  }
163 
164  /** \brief Get the cuda GPU device id in use **/
165  int
166  getDeviceId() const {return cuda_dev_id_;}
167 
168  private:
169  bool largest_object_; /** \brief only give back largest object **/
170  bool filter_rects_; /** \brief rectangular filter **/
171 
172  int cuda_dev_id_; /** \brief indicates which GPU to use for this **/
173  cudaDeviceProp cuda_dev_prop_;
174 
175  std::string cascade_file_name_;
176 
177  int rows_; // should default to 480
178  int cols_; // should default to 640
179 
180  HaarClassifierCascadeDescriptor haar_clas_casc_descr_;
181  NCVVectorAlloc<HaarStage64>* haar_stages_dev_;
182  NCVVectorAlloc<HaarStage64>* haar_stages_host_;
183  NCVVectorAlloc<HaarClassifierNode128>* haar_nodes_dev_;
184  NCVVectorAlloc<HaarClassifierNode128>* haar_nodes_host_;
185  NCVVectorAlloc<HaarFeature64>* haar_features_dev_;
186  NCVVectorAlloc<HaarFeature64>* haar_features_host_;
187 
188  INCVMemAllocator* gpu_allocator_;
189  INCVMemAllocator* cpu_allocator_;
190 
191  NCVMemStackAllocator* gpu_stack_allocator_;
192  NCVMemStackAllocator* cpu_stack_allocator_;
193 
194  NCVMemStackAllocator* gpu_counter_;
195  NCVMemStackAllocator* cpu_counter_;
196 
197  };
198  }
199  }
200 }
INCVMemAllocator (Interface)
Definition: NCV.hpp:403
NCVMemStackAllocator.
Definition: NCV.hpp:422
NCVVector (1D)
Definition: NCV.hpp:505
NCVStatus ncvHaarGetClassifierSize(const std::string &filename, Ncv32u &numStages, Ncv32u &numNodes, Ncv32u &numFeatures)
static NCVStatus loadFromNVBIN(const std::string &filename, HaarClassifierCascadeDescriptor &haar, std::vector< HaarStage64 > &haar_stages, std::vector< HaarClassifierNode128 > &haarClassifierNodes, std::vector< HaarFeature64 > &haar_features)
void process(pcl::PointCloud< pcl::RGB > &cloud, pcl::PointCloud< pcl::Intensity32u > &cloud_out)
Process step, this wraps the Nvidia code.
int getDeviceId() const
Get the cuda GPU device id in use.
std::string getCascadeFileName() const
FaceDetector(int cols, int rows)
This is the constructor.
void setLargestObject(bool largest_object)
largest object sets return configuration
void setDeviceId(int id)
Set the cuda GPU to use.
shared_ptr< FaceDetector > Ptr
Definition: face_detector.h:61
void setCascadeFileName(std::string cascadeFileName)
int configure(std::string cascade_file_name)
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)
NCVStatus loadFromXML2(const std::string &filename, HaarClassifierCascadeDescriptor &haar, std::vector< HaarStage64 > &haar_stages, std::vector< HaarClassifierNode128 > &haarClassifierNodes, std::vector< HaarFeature64 > &haar_features)
shared_ptr< const FaceDetector > ConstPtr
Definition: face_detector.h:62
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.
Defines functions, macros and traits for allocating and using memory.
Classifier cascade descriptor.