29 #include <VisionX/libraries/armem_human/aron/HumanPose.aron.generated.h>
40 RGBDPoseEstimationWithMemoryWriter::defaultName =
"RGBDPoseEstimationWithMemoryWriter";
44 RGBDPoseEstimationWithMemoryWriter::createPropertyDefinitions()
48 def->
required(properties.providerName,
"ImageProviderName");
50 def->optional(properties.enableMemory,
"humanMemory.enable",
"Enables or disables writing to the human memory.");
51 def->optional(properties.humanMemory.memoryName,
"humanMemory.memory_name",
"Name of the human memory.");
52 def->optional(properties.humanMemory.coreSegmentName,
"humanMemory.core_segment_name",
"Name of the core segment in the human memory.");
54 RGBDOpenPoseEstimationComponentPluginUser::postCreatePropertyDefinitions(def);
60 RGBDPoseEstimationWithMemoryWriter::getDefaultName()
const
62 return RGBDPoseEstimationWithMemoryWriter::defaultName;
67 RGBDPoseEstimationWithMemoryWriter::GetDefaultName()
69 return RGBDPoseEstimationWithMemoryWriter::defaultName;
74 RGBDPoseEstimationWithMemoryWriter::reportEntities()
76 if (properties.enableMemory)
87 update.referencedTime = ts;
89 for (
auto& [_, humanPose] : openposeResult3D)
91 auto pose = humanPose.keypointMap;
93 armarx::human::arondto::HumanPose dto;
94 dto.poseModelId = op_settings.model_pose;
96 dto.humanTrackingId = std::nullopt;
98 for (
auto& [name, keypoint] : pose)
100 armarx::human::arondto::PoseKeypoint kp;
101 kp.confidence = keypoint.confidence;
104 posGlobal.header.agent = localRobot->getName();
106 posGlobal.position.x() = keypoint.globalX;
107 posGlobal.position.y() = keypoint.globalY;
108 posGlobal.position.z() = keypoint.globalZ;
110 toAron(kp.positionGlobal.emplace(), positionGlobal);
112 FramedPosition pos(Eigen::Vector3f(keypoint.x, keypoint.y, keypoint.z), cameraNodeName, localRobot->getName());
114 toAron(kp.positionRobot.emplace(), posRobot);
116 dto.keypoints[keypoint.label] = kp;
119 update.instancesData.push_back(dto.toAron());
130 RGBDOpenPoseEstimationComponentPluginUser::reportEntities();
133 void RGBDPoseEstimationWithMemoryWriter::onInitImageProcessor()
135 RGBDOpenPoseEstimationComponentPluginUser::preOnInitImageProcessor();
136 usingImageProvider(properties.providerName);
138 timeoutCounter2d = 0;
139 readErrorCounter2d = 0;
143 void RGBDPoseEstimationWithMemoryWriter::onConnectImageProcessor()
145 RGBDOpenPoseEstimationComponentPluginUser::preOnConnectImageProcessor();
147 if (properties.enableMemory)
152 humanMemoryWriter = memoryNameSystem().useWriter(properties.humanMemory);
166 imageProviderInfo = getImageProvider(properties.providerName, imageDisplayType);
167 rgbImageFormat = imageProviderInfo.imageFormat;
169 numImages =
static_cast<unsigned int>(imageProviderInfo.numberImages);
176 imageBuffer =
new CByteImage*[2];
177 openposeResultImage =
new CByteImage*[1];
183 enableResultImages(1, imageProviderInfo.imageFormat.dimension, imageProviderInfo.imageFormat.type);
187 RGBDOpenPoseEstimationComponentPluginUser::postOnConnectImageProcessor();
190 void RGBDPoseEstimationWithMemoryWriter::onDisconnectImageProcessor()
192 RGBDOpenPoseEstimationComponentPluginUser::preOnDisconnectImageProcessor();
194 delete[] imageBuffer;
196 RGBDOpenPoseEstimationComponentPluginUser::postOnDisconnectImageProcessor();
199 void RGBDPoseEstimationWithMemoryWriter::onExitImageProcessor()
203 void RGBDPoseEstimationWithMemoryWriter::process()
208 if (result_image_ready)
210 std::lock_guard outputImage_lock(openposeResultImageMutex);
212 provideResultImages(openposeResultImage, imageMetaInfo);
216 if (!waitForImages(properties.providerName))
220 <<
" (#timeout " << timeoutCounter2d
221 <<
", #read error " << readErrorCounter2d
222 <<
", #success " << sucessCounter2d <<
")";
226 std::lock_guard lock_images(imageBufferMutex);
227 if (
static_cast<unsigned int>(getImages(properties.providerName, imageBuffer, imageMetaInfo)) != numImages)
229 ++readErrorCounter2d;
231 <<
" (#timeout " << timeoutCounter2d
232 <<
", #read error " << readErrorCounter2d
233 <<
", #success " << sucessCounter2d <<
")";
241 std::lock_guard lock_rgb(rgbImageBufferMutex);
242 std::lock_guard lock_depth(depthImageBufferMutex);
243 ::ImageProcessor::CopyImage(imageBuffer[0], rgbImageBuffer);
244 ::ImageProcessor::CopyImage(imageBuffer[1], depthImageBuffer);
246 timestamp_of_update = imageMetaInfo->timeProvided;