27#include <VirtualRobot/MathTools.h>
42#include "Image/ByteImage.h"
43#include "Image/ImageProcessor.h"
44#include <Calibration/Calibration.h>
45#include <Color/ColorParameterSet.h>
48#include "Locators/VisualTargetLocator.h"
70 stereoMatcher =
new CStereoMatcher();
98 ARMARX_IMPORTANT <<
" xxxxxxxxxxx BigBowlLocalization initRecognizer!!!!!!!!!!";
100 std::string colorParameterFilename =
104 colorParameterFilename))
106 ARMARX_ERROR <<
"Could not find color parameter file in ArmarXDataPath: "
107 << colorParameterFilename;
111 ARMARX_VERBOSE <<
"Color parameter file name: " << colorParameterFilename;
113 visualTargetLocator =
new CVisualTargetLocator();
119 int nMinPixelsPerRegion =
getProperty<int>(
"nMinPixelsPerRegion").getValue();
126 visualTargetLocator->SetParameters(nMinPixelsPerRegion,
133 colorParameterSet =
new CColorParameterSet();
134 colorParameterSet->LoadFromFile(colorParameterFilename.c_str());
141 showSegmentedResultImages =
getProperty<bool>(
"ShowSegmentedResultImages").getValue();
143 if (!showSegmentedResultImages)
151 memoryx::ObjectLocalizationResultList
159 << (IceUtil::Time::now() -
161 .toMilliSecondsDouble()
164 localRobot, robotStateComponent,
imageMetaInfo->timeProvided))
167 <<
"Failed to synchronize local robot - results are probably wrong";
174 const std::string agentName = localRobot->getName();
176 Eigen::Vector3f expectedPositionVec;
177 expectedPositionVec << 0, 600, 1000;
178 const std::string rootFrameName = localRobot->getRootNode()->getName();
183 memoryx::ObjectLocalizationResultList resultList;
188 Vec3d bigBowlPosition;
189 int numFoundBlobs = 0;
192 ARMARX_INFO <<
"Found " << numFoundBlobs <<
" blobs.";
194 if (numFoundBlobs == 0)
201 Eigen::Vector3f position;
202 position << bigBowlPosition.x, bigBowlPosition.y, bigBowlPosition.z;
203 float diffToExpectedPosition = (position - expectedPosition->toEigen()).norm();
205 if (diffToExpectedPosition < 1200)
208 memoryx::ObjectLocalizationResult result;
209 result.recognitionCertainty = 0.96f;
210 result.objectClassName = objectClassNames.at(0);
214 positionPtr->changeFrame(localRobot, localRobot->getRootNode()->getName());
215 positionPtr->z = 1030;
216 result.position = positionPtr;
217 Eigen::Matrix4f orientation = Eigen::Matrix4f::Identity();
218 VirtualRobot::MathTools::rpy2eigen4f(-
M_PI / 2, 0, 0, orientation);
222 result.orientation = ori;
226 resultList.push_back(result);
229 ARMARX_INFO <<
"position >> x: " << positionPtr->x <<
" y: " << positionPtr->y
230 <<
" z: " << positionPtr->z <<
" frame: " << positionPtr->frame;
232 ARMARX_INFO <<
"globalposition >> x: " << globalPosPtr->x
233 <<
" y: " << globalPosPtr->y <<
" z: " << globalPosPtr->z
234 <<
" frame: " << globalPosPtr->frame;
238 Eigen::Matrix4f currPose;
239 currPose.setIdentity();
241 currPose(0, 3) = globalPosPtr->x;
242 currPose(1, 3) = globalPosPtr->y;
243 currPose(2, 3) = globalPosPtr->z;
247 Eigen::Vector3f v(100, 100, 100);
252 "objLocalizationLayer", poseGlobal, s, armarx::DrawColor{1, 0, 0, 1});
263 <<
"Object is too far away from expected position: "
264 << (int)diffToExpectedPosition;
270 ARMARX_INFO <<
"Vision is switched off, returning fake result";
272 memoryx::ObjectLocalizationResult result;
273 result.recognitionCertainty = 0.8f;
274 result.objectClassName = objectClassNames.at(0);
276 result.position = expectedPosition;
278 Eigen::Matrix3f orientation = Eigen::Matrix3f::Identity();
283 resultList.push_back(result);
292 BigBowlLocalization::drawCrossInImage(CByteImage* image, Eigen::Vector3f point,
bool leftCamera)
294 Vec3d positionIVT = {point(0), point(1), point(2)};
295 Vec2d projectedPoint;
309 ARMARX_INFO <<
"projectedPoint.x :" << projectedPoint.x
310 <<
" projectedPoint.y: " << projectedPoint.y;
312 if (size < projectedPoint.x && size < projectedPoint.y &&
313 projectedPoint.x < image->width - size - 1 &&
314 projectedPoint.y < image->height - size - 3)
316 for (
int i = -size; i <= size; i++)
318 int indexHorizontalLine =
319 3 * ((int)projectedPoint.y * image->width + (int)projectedPoint.x + i);
320 int indexVerticalLine =
321 3 * (((int)projectedPoint.y + i) * image->width + (int)projectedPoint.x);
322 image->pixels[indexHorizontalLine] = 255;
323 image->pixels[indexHorizontalLine + 1] = 255;
324 image->pixels[indexHorizontalLine + 2] = 255;
325 image->pixels[indexVerticalLine] = 255;
326 image->pixels[indexVerticalLine + 1] = 255;
327 image->pixels[indexVerticalLine + 2] = 255;
333 BigBowlLocalization::locateBowl(CByteImage** cameraImages,
335 CByteImage** resultImages)
337 int numberOfSegments = 0;
338 CByteImage* imageHSVLeft =
340 CByteImage* imageHSVRight =
342 CByteImage* imageFiltered =
344 CByteImage* imgLeftGray =
346 CByteImage* imgRightGray =
349 ::ImageProcessor::CalculateHSVImage(
cameraImages[0], imageHSVLeft);
350 ::ImageProcessor::CalculateHSVImage(
cameraImages[1], imageHSVRight);
351 ::ImageProcessor::ConvertImage(
cameraImages[0], imgLeftGray);
352 ::ImageProcessor::ConvertImage(
cameraImages[1], imgRightGray);
353 ::ImageProcessor::Zero(imageFiltered);
355 int ThesholdHMinValue = 4;
356 int ThesholdHMaxValue = 20;
357 int ThesholdSMinValue = 220;
358 int ThesholdSMaxValue = 255;
360 int imagePosXLeft = 0;
361 int imagePosYLeft = 0;
362 int totalPixelLeft = 0;
363 int imagePosXRight = 0;
364 int imagePosYRight = 0;
365 int totalPixelRight = 0;
369 for (
int i = deltaROI; i < imageHSVLeft->width - deltaROI; i++)
371 for (
int j = deltaROI; j < imageHSVLeft->height - deltaROI; j++)
373 int pixelIndex = (i + j * imageHSVLeft->width) * imageHSVLeft->bytesPerPixel;
374 double hVal = (double)imageHSVLeft->pixels[pixelIndex];
375 double sVal = (double)imageHSVLeft->pixels[pixelIndex + 1];
377 if ((hVal > ThesholdHMinValue && hVal < ThesholdHMaxValue) &&
378 (sVal > ThesholdSMinValue && sVal < ThesholdSMaxValue))
380 imageFiltered->pixels[pixelIndex] =
cameraImages[0]->pixels[pixelIndex];
381 imageFiltered->pixels[pixelIndex + 1] =
cameraImages[0]->pixels[pixelIndex + 1];
382 imageFiltered->pixels[pixelIndex + 2] =
cameraImages[0]->pixels[pixelIndex + 2];
389 ARMARX_INFO <<
"totalPixel >> left " << totalPixelLeft;
393 for (
int i = deltaROI; i < imageHSVRight->width - deltaROI; i++)
395 for (
int j = deltaROI; j < imageHSVRight->height - deltaROI; j++)
397 int pixelIndex = (i + j * imageHSVRight->width) * imageHSVRight->bytesPerPixel;
398 double hVal = (double)imageHSVRight->pixels[pixelIndex];
399 double sVal = (double)imageHSVRight->pixels[pixelIndex + 1];
401 if ((hVal > ThesholdHMinValue && hVal < ThesholdHMaxValue) &&
402 (sVal > ThesholdSMinValue && sVal < ThesholdSMaxValue))
410 ARMARX_INFO <<
"totalPixel >> right " << totalPixelRight;
412 if (totalPixelLeft > 10000 && totalPixelRight > 10000)
414 numberOfSegments = 1;
420 ::ImageProcessor::Zero(imageFiltered);
422 numberOfSegments = 0;
423 return numberOfSegments;
426 Vec2d imageCoorLeft, imageCoorRight;
427 imageCoorLeft.x = (int)imagePosXLeft / totalPixelLeft;
428 imageCoorLeft.y = (int)imagePosYLeft / totalPixelLeft;
429 imageCoorRight.x = (int)imagePosXRight / totalPixelRight;
430 imageCoorRight.y = (int)imagePosYRight / totalPixelRight;
432 ARMARX_INFO <<
"imageCoorLeft x: " << imageCoorLeft.x <<
" y: " << imageCoorLeft.y;
433 ARMARX_INFO <<
"imageCoorRight x: " << imageCoorRight.x <<
" y: " << imageCoorRight.y;
435 if (imageCoorLeft.x < 250 || imageCoorLeft.x > 470 || imageCoorLeft.y < 150 ||
436 imageCoorLeft.y > 320)
440 ::ImageProcessor::Zero(imageFiltered);
442 numberOfSegments = 0;
443 return numberOfSegments;
446 Vec2d vCorrespondingPointRight;
447 const int nDispMin = stereoMatcher->GetDisparityEstimate(10000);
448 const int nDispMax = stereoMatcher->GetDisparityEstimate(500);
452 int nMatchingResult = stereoMatcher->Match(imgLeftGray,
454 (
int)imageCoorLeft.x,
455 (
int)imageCoorLeft.y,
459 vCorrespondingPointRight,
465 ARMARX_INFO <<
"nMatchingResult " << nMatchingResult;
469 if (nMatchingResult <= 0)
473 ::ImageProcessor::Zero(imageFiltered);
475 numberOfSegments = 0;
476 return numberOfSegments;
480 int deltaCenter = 10;
481 for (
int i = imageCoorLeft.x - deltaCenter; i < imageCoorLeft.x + deltaCenter; i++)
483 for (
int j = imageCoorLeft.y - deltaCenter; j < imageCoorLeft.y + deltaCenter; j++)
485 int pixelIndex = (i + j * imageHSVLeft->width) * imageHSVLeft->bytesPerPixel;
486 imageFiltered->pixels[pixelIndex] = 255;
487 imageFiltered->pixels[pixelIndex + 1] = 255;
488 imageFiltered->pixels[pixelIndex + 2] = 255;
506 return numberOfSegments;
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
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)
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
Implements a Variant type for timestamps.
bool initRecognizer() override
Initializes segmentable recognition.
void onExitObjectLocalizerProcessor() override
void onInitObjectLocalizerProcessor() override
armarx::DebugDrawerInterfacePrx debugDrawerPrx
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localize one or both hand markers
void onConnectObjectLocalizerProcessor() override
Initialize stuff here?
CByteImage * cameraImages[2]
bool getImagesAreUndistorted() const
Retrieve whether images are undistorted.
std::string referenceFrameName
bool getResultImagesEnabled() const
Retrieve whether result images are enabled.
memoryx::MultivariateNormalDistributionPtr calculateLocalizationUncertainty(Vec2d left_point, Vec2d right_point)
Calculate 3D uncertainty from two 2d points in left and right camera.
armarx::MetaInfoSizeBasePtr imageMetaInfo
CStereoCalibration * getStereoCalibration() const
Retrieve stereo calibration corresponding to image provider.
CByteImage ** resultImages
#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_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
VectorXD< 2, double > Vec2d
IceInternal::Handle< Vector3 > Vector3Ptr
IceInternal::Handle< Pose > PosePtr
IceInternal::Handle< FramedPosition > FramedPositionPtr
IceInternal::Handle< FramedOrientation > FramedOrientationPtr