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 
26 
27 #include <opencv2/core/core.hpp>
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 
37 namespace armarx
38 {
39  /**
40  * @class FaceRecognitionPropertyDefinitions
41  * @brief
42  */
45  {
46  public:
49  {
50  defineOptionalProperty<double>("scaleFactor", 1.02, "scale factor for the HAAR classifier");
51  defineOptionalProperty<int>("minNeighbors", 2, "number of neighbors for the HAAR classifier");
52  defineOptionalProperty<std::string>("trainingDataPath", "VisionX/examples/faces", "folder containing the training images");
53  defineOptionalProperty<std::string>("classifierFileName", "VisionX/examples/haarcascades/haarcascade_frontalface_alt.xml", "path to the HAAR classifier");
54  }
55  };
56 
57  /**
58  * @defgroup Component-FaceRecognition FaceRecognition
59  * @ingroup VisionX-Components
60  * A description of the component FaceRecognition.
61  *
62  * @class FaceRecognition
63  * @ingroup Component-FaceRecognition
64  * @brief Brief description of class FaceRecognition.
65  *
66  * Detailed description of class FaceRecognition.
67  */
70  {
71  public:
72  /**
73  * @see armarx::ManagedIceObject::getDefaultName()
74  */
75  std::string getDefaultName() const override
76  {
77  return "FaceRecognition";
78  }
79 
80  protected:
81 
82  /**
83  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
84  */
85  void onInitObjectLocalizerProcessor() override;
86 
87  /**
88  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
89  */
90  void onConnectObjectLocalizerProcessor() override;
91 
92  /**
93  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
94  */
95  void onExitObjectLocalizerProcessor() override;
96 
97  /**
98  * Add a memory entity representing the hand marker in order to set its properties
99  *
100  * @param objectClassEntity entity containing all information available for the object class
101  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
102  *
103  * @return success of adding this entity
104  */
105  memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector<std::string>& objectClassNames, CByteImage** cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage** resultImages) override;
106 
107  /**
108  * Initializes segmentable recognition
109  *
110  * @return success
111  */
112  bool initRecognizer() override;
113 
114  /**
115  * Add a memory entity representing the hand marker in order to set its properties
116  *
117  * @param objectClassEntity entity containing all information available for the object class
118  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
119  *
120  * @return success of adding this entity
121  */
122  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity, const memoryx::GridFileManagerPtr& fileManager) override;
123 
124  /**
125  * @see PropertyUser::createPropertyDefinitions()
126  */
128 
129  private:
130 
131  cv::Ptr<cv::face::FaceRecognizer> model;
132 
133  cv::CascadeClassifier classifier;
134 
135  std::map<int, std::string> labels;
136 
137  double scaleFactor;
138  int minNeighbors;
139 
140  cv::Size faceImageSize;
141 
142  CStereoMatcher* stereoMatcher;
143 
144  };
145 }
146 
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:374
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:233
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:132
armarx::FaceRecognition
Brief description of class FaceRecognition.
Definition: FaceRecognition.h:68
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::ObjectLocalizerProcessorPropertyDefinitions::ObjectLocalizerProcessorPropertyDefinitions
ObjectLocalizerProcessorPropertyDefinitions(std::string prefix)
Definition: ObjectLocalizerProcessor.h:83
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:139
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:375
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
armarx::FaceRecognition::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Definition: FaceRecognition.cpp:116
armarx::FaceRecognitionPropertyDefinitions
Definition: FaceRecognition.h:43
armarx::FaceRecognitionPropertyDefinitions::FaceRecognitionPropertyDefinitions
FaceRecognitionPropertyDefinitions(std::string prefix)
Definition: FaceRecognition.h:47
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:372
armarx::FaceRecognition::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: FaceRecognition.cpp:45
armarx::FaceRecognition::getDefaultName
std::string getDefaultName() const override
Definition: FaceRecognition.h:75
armarx::FaceRecognition::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: FaceRecognition.cpp:127
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
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:28
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:107