FaceRecognition.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package VisionX::ArmarXObjects::FaceRecognition
17  * @author Markus Grotz ( markus dot grotz at kit dot edu )
18  * @date 2016
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <opencv2/core/core.hpp>
26 
28 //#include <opencv2/contrib/contrib.hpp>
29 #include <opencv2/face.hpp>
30 #include <opencv2/highgui/highgui.hpp>
31 #include <opencv2/imgproc/imgproc.hpp>
32 #include <opencv2/objdetect/objdetect.hpp>
33 
34 #include <Image/StereoMatcher.h>
35 
36 namespace armarx
37 {
38  /**
39  * @class FaceRecognitionPropertyDefinitions
40  * @brief
41  */
44  {
45  public:
48  {
49  defineOptionalProperty<double>(
50  "scaleFactor", 1.02, "scale factor for the HAAR classifier");
51  defineOptionalProperty<int>(
52  "minNeighbors", 2, "number of neighbors for the HAAR classifier");
53  defineOptionalProperty<std::string>("trainingDataPath",
54  "VisionX/examples/faces",
55  "folder containing the training images");
56  defineOptionalProperty<std::string>(
57  "classifierFileName",
58  "VisionX/examples/haarcascades/haarcascade_frontalface_alt.xml",
59  "path to the HAAR classifier");
60  }
61  };
62 
63  /**
64  * @defgroup Component-FaceRecognition FaceRecognition
65  * @ingroup VisionX-Components
66  * A description of the component FaceRecognition.
67  *
68  * @class FaceRecognition
69  * @ingroup Component-FaceRecognition
70  * @brief Brief description of class FaceRecognition.
71  *
72  * Detailed description of class FaceRecognition.
73  */
75  {
76  public:
77  /**
78  * @see armarx::ManagedIceObject::getDefaultName()
79  */
80  std::string
81  getDefaultName() const override
82  {
83  return "FaceRecognition";
84  }
85 
86  protected:
87  /**
88  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
89  */
90  void onInitObjectLocalizerProcessor() override;
91 
92  /**
93  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
94  */
95  void onConnectObjectLocalizerProcessor() override;
96 
97  /**
98  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
99  */
100  void onExitObjectLocalizerProcessor() override;
101 
102  /**
103  * Add a memory entity representing the hand marker in order to set its properties
104  *
105  * @param objectClassEntity entity containing all information available for the object class
106  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
107  *
108  * @return success of adding this entity
109  */
110  memoryx::ObjectLocalizationResultList
111  localizeObjectClasses(const std::vector<std::string>& objectClassNames,
112  CByteImage** cameraImages,
113  armarx::MetaInfoSizeBasePtr imageMetaInfo,
114  CByteImage** resultImages) override;
115 
116  /**
117  * Initializes segmentable recognition
118  *
119  * @return success
120  */
121  bool initRecognizer() override;
122 
123  /**
124  * Add a memory entity representing the hand marker in order to set its properties
125  *
126  * @param objectClassEntity entity containing all information available for the object class
127  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
128  *
129  * @return success of adding this entity
130  */
131  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
132  const memoryx::GridFileManagerPtr& fileManager) override;
133 
134  /**
135  * @see PropertyUser::createPropertyDefinitions()
136  */
138 
139  private:
140  cv::Ptr<cv::face::FaceRecognizer> model;
141 
142  cv::CascadeClassifier classifier;
143 
144  std::map<int, std::string> labels;
145 
146  double scaleFactor;
147  int minNeighbors;
148 
149  cv::Size faceImageSize;
150 
151  CStereoMatcher* stereoMatcher;
152  };
153 } // namespace armarx
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:431
armarx::FaceRecognition::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: FaceRecognition.cpp:121
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::FaceRecognition::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FaceRecognition.cpp:260
armarx::FaceRecognition::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add a memory entity representing the hand marker in order to set its properties.
Definition: FaceRecognition.cpp:134
armarx::FaceRecognition
Brief description of class FaceRecognition.
Definition: FaceRecognition.h:74
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::ObjectLocalizerProcessorPropertyDefinitions::ObjectLocalizerProcessorPropertyDefinitions
ObjectLocalizerProcessorPropertyDefinitions(std::string prefix)
Definition: ObjectLocalizerProcessor.h:82
armarx::FaceRecognition::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
Add a memory entity representing the hand marker in order to set its properties.
Definition: FaceRecognition.cpp:142
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:432
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
armarx::FaceRecognition::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Definition: FaceRecognition.cpp:115
armarx::FaceRecognitionPropertyDefinitions
Definition: FaceRecognition.h:42
armarx::FaceRecognitionPropertyDefinitions::FaceRecognitionPropertyDefinitions
FaceRecognitionPropertyDefinitions(std::string prefix)
Definition: FaceRecognition.h:46
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:429
armarx::FaceRecognition::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: FaceRecognition.cpp:45
armarx::FaceRecognition::getDefaultName
std::string getDefaultName() const override
Definition: FaceRecognition.h:81
armarx::FaceRecognition::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: FaceRecognition.cpp:128
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:128