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>
53 usingProxy(
"FaceRecognition");
54 usingProxy(
"LongtermMemory");
55 usingProxy(getProperty<std::string>(
"ImageProviderName").getValue());
58 offeringTopic(
"TextToSpeech");
65 getProxy(faceReg,
"FaceRecognition");
66 getProxy(ltm,
"LongtermMemory");
67 getProxy(imageProvider, getProperty<std::string>(
"ImageProviderName").getValue());
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);
75 tts = getTopic<armarx::TextListenerInterfacePrx>(
"TextToSpeech");
76 if (!ltm->hasSegment(faceSegmentName))
78 faceSegmentPrx = memoryx::EntityMemorySegmentInterfacePrx::checkedCast(
79 ltm->addGenericSegment(faceSegmentName));
84 memoryx::EntityMemorySegmentInterfacePrx::checkedCast(ltm->getSegment(faceSegmentName));
89 DeepFaceRecognition::createPropertyDefinitions()
95 memoryx::ObjectLocalizationResultList
100 memoryx::ObjectLocalizationResultList result;
104 auto faceLocations = faceReg->calculateFaceLocations();
106 << faceLocations.size() <<
" faces";
107 auto agentName = getProperty<std::string>(
"AgentName").getValue();
108 auto cameraFrame = getProperty<std::string>(
"CameraFrameName").getValue();
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;
125 float faceHeightPixel = faceLocation.bottomRight.e1 - faceLocation.topLeft.e1;
127 calibration->GetCameraParameters().focalLength.y * 160.f / (faceHeightPixel);
128 this->calibration->ImageToCameraCoordinates(
131 <<
": " << cameraCoords.x <<
", " << cameraCoords.y
135 Eigen::Vector3f(cameraCoords.x, cameraCoords.y,
distance), cameraFrame, agentName);
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());
157 IceUtil::Time::secondsDouble(getProperty<float>(
"GreetAgainDelay").getValue()) <
163 if (updateFaceMemory)
180 face->setName(faceLocation.label);
182 face->putAttribute(
"ImagePosition",
new armarx::Vector2(centerX, centerY));
185 float prob = updateAndCheckFaceExistenceProbability(faceLocation);
187 if (prob > getProperty<float>(
"GreetThreshold").getValue())
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);
204 visionx::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();)
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)
238 double confidence = timeConfPair.second;
239 double tDiff = (t - now).toMilliSecondsDouble() * 0.001;
240 double weight = gaussianBellCurve(tDiff);
242 sum += confidence * weight;