25#include <Eigen/Geometry>
27#include <SimoxUtility/algorithm/string/string_tools.h>
37#include <Calibration/Calibration.h>
38#include <Image/ImageProcessor.h>
39#include <Image/IplImageAdaptor.h>
40#include <Image/PrimitivesDrawer.h>
41#include <Image/PrimitivesDrawerCV.h>
65 getProxy(faceReg,
"FaceRecognition");
71 this->calibration.reset(
new CCalibration());
72 calibration->SetCameraParameters(
73 987.99, 956.82, 639.32, 415.64, 0, 0, 0, 0, Math3d::unit_mat, Math3d::zero_vec, 1280, 720);
76 if (!ltm->hasSegment(faceSegmentName))
78 faceSegmentPrx = memoryx::EntityMemorySegmentInterfacePrx::checkedCast(
79 ltm->addGenericSegment(faceSegmentName));
84 memoryx::EntityMemorySegmentInterfacePrx::checkedCast(ltm->getSegment(faceSegmentName));
95memoryx::ObjectLocalizationResultList
100 memoryx::ObjectLocalizationResultList result;
104 auto faceLocations = faceReg->calculateFaceLocations();
106 << faceLocations.size() <<
" faces";
109 for (visionx::FaceLocation faceLocation : faceLocations)
112 memoryx::EntityPtr::dynamicCast(faceSegmentPrx->getEntityByName(faceLocation.label));
113 bool updateFaceMemory =
true;
115 << faceLocation.topLeft.e1 <<
", " << faceLocation.bottomRight.e0 <<
", "
116 << faceLocation.bottomRight.e1;
117 float centerX = (faceLocation.bottomRight.e0 + faceLocation.topLeft.e0) * 0.5f;
118 float centerY = (faceLocation.bottomRight.e1 + faceLocation.topLeft.e1) * 0.5f;
119 memoryx::ObjectLocalizationResult r;
120 r.objectClassName =
"face";
121 r.instanceName = faceLocation.label;
122 Eigen::Matrix3f ori = Eigen::Matrix3f::Identity();
125 float faceHeightPixel = faceLocation.bottomRight.e1 - faceLocation.topLeft.e1;
127 calibration->GetCameraParameters().focalLength.y * 160.f / (faceHeightPixel);
128 this->calibration->ImageToCameraCoordinates(
129 Vec2d{centerX, centerY}, cameraCoords,
distance,
false);
131 <<
": " << cameraCoords.x <<
", " << cameraCoords.y
135 Eigen::Vector3f(cameraCoords.x, cameraCoords.y,
distance), cameraFrame, agentName);
136 Eigen::Matrix3f
id = Eigen::Matrix3f::Identity();
138 r.recognitionCertainty = 0.7f;
139 Eigen::Vector3f cov(10, 10, 10000);
145 if (faceLocation.label ==
"Unknown")
149 if (oldFace && oldFace->hasAttribute(
"LastGreetingTime"))
152 VariantPtr::dynamicCast(oldFace->getAttribute(
"LastGreetingTime")->getValue());
163 if (updateFaceMemory)
180 face->setName(faceLocation.label);
182 face->putAttribute(
"ImagePosition",
new armarx::Vector2(centerX, centerY));
185 float prob = updateAndCheckFaceExistenceProbability(faceLocation);
190 auto tts_label = simox::alg::replace_all(faceLocation.label,
"mirko",
"mir ko");
192 tts->reportTextWithParams(
"Hello %1%.", {tts_label});
198 faceSegmentPrx->upsertEntityByName(faceLocation.label, face);
204visionx::DeepFaceRecognition::updateAndCheckFaceExistenceProbability(
205 const visionx::FaceLocation& faceLocation)
207 auto& timeConfList = faceConfidenceHistory[faceLocation.label];
209 double filterRadius = getProperty<float>(
"FilterRadius").getValue();
210 double sigma = filterRadius / 2.5;
211 double sigmaSquare = sigma * sigma;
212 auto gaussianBellCurve = [&](
double x) {
return exp(-
double((
x) * (
x)) / (sigmaSquare)); };
214 auto now = IceUtil::Time::now();
216 for (
auto it = timeConfList.begin(); it != timeConfList.end();)
218 IceUtil::Time t = it->first;
220 double tDiff = (t - now).toMilliSecondsDouble() * 0.001;
221 double weight = gaussianBellCurve(tDiff);
225 it = timeConfList.erase(it);
233 timeConfList.push_back(std::make_pair(now, faceLocation.confidence));
235 for (
auto& timeConfPair : timeConfList)
237 IceUtil::Time t = timeConfPair.first;
238 double confidence = timeConfPair.second;
239 double tDiff = (t - now).toMilliSecondsDouble() * 0.001;
240 double weight = gaussianBellCurve(tDiff);
242 sum += confidence * weight;
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
The FramedOrientation class.
The FramedPosition class.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Implements a Variant type for timestamps.
static TimestampVariantPtr nowPtr()
static EntityPtr CreateGenericEntity()
Creates an entity without any convenience getter/setter functions.
The MultivariateNormalDistribution class.
void onInitComponent() override
Pure virtual hook for the subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Add a memory entity representing the hand marker in order to set its properties.
memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList &classes, const Ice::Current &) override
void onConnectComponent() override
Pure virtual hook for the subclass.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
double distance(const Point &a, const Point &b)