39 #include <Calibration/Calibration.h>
40 #include <Color/ColorParameterSet.h>
41 #include "Image/ByteImage.h"
42 #include "Image/ImageProcessor.h"
45 #include "Locators/VisualTargetLocator.h"
61 useVision = getProperty<bool>(
"UseVision").getValue();
62 objectColor = getProperty<ObjectColor>(
"BlobColor").getValue();
67 stereoMatcher =
new CStereoMatcher();
72 robotStateComponent = getProxy<armarx::RobotStateComponentInterfacePrx>(
"RobotStateComponent");
76 debugDrawerPrx = getTopic<armarx::DebugDrawerInterfacePrx>(
"DebugDrawerUpdates");
90 ARMARX_IMPORTANT <<
" xxxxxxxxxxx BigBowlLocalization initRecognizer!!!!!!!!!!" ;
92 std::string colorParameterFilename = getProperty<std::string>(
"ColorParameterFile").getValue();
96 ARMARX_ERROR <<
"Could not find color parameter file in ArmarXDataPath: " << colorParameterFilename;
100 ARMARX_VERBOSE <<
"Color parameter file name: " << colorParameterFilename;
102 visualTargetLocator =
new CVisualTargetLocator();
108 int nMinPixelsPerRegion = getProperty<int>(
"nMinPixelsPerRegion").getValue();
109 double dMaxEpipolarDiff = getProperty<double>(
"dMaxEpipolarDiff").getValue();
110 double dMinFilledRatio = getProperty<double>(
"dMinFilledRatio").getValue();
111 double dMaxSideRatio = getProperty<double>(
"dMaxSideRatio").getValue();
112 double dMinSize = getProperty<double>(
"dMinSize").getValue();
113 double dMaxSize = getProperty<double>(
"dMaxSize").getValue();
115 visualTargetLocator->SetParameters(nMinPixelsPerRegion, dMaxEpipolarDiff, dMinFilledRatio, dMaxSideRatio, dMinSize, dMaxSize);
117 colorParameterSet =
new CColorParameterSet();
118 colorParameterSet->LoadFromFile(colorParameterFilename.c_str());
125 showSegmentedResultImages = getProperty<bool>(
"ShowSegmentedResultImages").getValue();
127 if (!showSegmentedResultImages)
136 memoryx::ObjectLocalizationResultList
BigBowlLocalization::localizeObjectClasses(
const std::vector<std::string>& objectClassNames, CByteImage** cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage** resultImages)
149 const std::string agentName = localRobot->getName();
151 Eigen::Vector3f expectedPositionVec;
152 expectedPositionVec << 0, 600, 1000;
153 const std::string rootFrameName = localRobot->getRootNode()->getName();
157 memoryx::ObjectLocalizationResultList resultList;
162 Vec3d bigBowlPosition;
163 int numFoundBlobs = 0;
166 ARMARX_INFO <<
"Found " << numFoundBlobs <<
" blobs.";
168 if (numFoundBlobs == 0)
175 Eigen::Vector3f position;
176 position << bigBowlPosition.x, bigBowlPosition.y, bigBowlPosition.z;
177 float diffToExpectedPosition = (position - expectedPosition->toEigen()).
norm();
179 if (diffToExpectedPosition < 1200)
182 memoryx::ObjectLocalizationResult result;
183 result.recognitionCertainty = 0.96f;
184 result.objectClassName = objectClassNames.at(0);
187 positionPtr->changeFrame(localRobot, localRobot->getRootNode()->getName());
188 positionPtr->z = 1030;
189 result.position = positionPtr;
191 VirtualRobot::MathTools::rpy2eigen4f(-
M_PI / 2, 0, 0, orientation);
194 result.orientation = ori;
198 resultList.push_back(result);
201 ARMARX_INFO <<
"position >> x: " << positionPtr->x <<
" y: " << positionPtr->y
202 <<
" z: " << positionPtr->z <<
" frame: " << positionPtr->frame;
204 ARMARX_INFO <<
"globalposition >> x: " << globalPosPtr->x <<
" y: " << globalPosPtr->y
205 <<
" z: " << globalPosPtr->z <<
" frame: " << globalPosPtr->frame;
210 currPose.setIdentity();
212 currPose(0, 3) = globalPosPtr->x;
213 currPose(1, 3) = globalPosPtr->y;
214 currPose(2, 3) = globalPosPtr->z;
218 Eigen::Vector3f
v(100, 100, 100);
222 debugDrawerPrx->setBoxDebugLayerVisu(
"objLocalizationLayer", poseGlobal,
s, armarx::DrawColor {1, 0, 0, 1});
239 ARMARX_INFO <<
"Vision is switched off, returning fake result";
241 memoryx::ObjectLocalizationResult result;
242 result.recognitionCertainty = 0.8f;
243 result.objectClassName = objectClassNames.at(0);
245 result.position = expectedPosition;
251 resultList.push_back(result);
261 void BigBowlLocalization::drawCrossInImage(CByteImage* image, Eigen::Vector3f point,
bool leftCamera)
263 Vec3d positionIVT = {point(0), point(1), point(2)};
264 Vec2d projectedPoint;
276 ARMARX_INFO <<
"projectedPoint.x :" << projectedPoint.x <<
" projectedPoint.y: " << projectedPoint.y;
278 if (size < projectedPoint.x && size < projectedPoint.y && projectedPoint.x < image->width - size - 1 && projectedPoint.y < image->height - size - 3)
280 for (
int i = -size; i <= size; i++)
282 int indexHorizontalLine = 3 * ((int)projectedPoint.y * image->width + (
int)projectedPoint.x + i);
283 int indexVerticalLine = 3 * (((int)projectedPoint.y + i) * image->width + (int)projectedPoint.x);
284 image->pixels[indexHorizontalLine] = 255;
285 image->pixels[indexHorizontalLine + 1] = 255;
286 image->pixels[indexHorizontalLine + 2] = 255;
287 image->pixels[indexVerticalLine] = 255;
288 image->pixels[indexVerticalLine + 1] = 255;
289 image->pixels[indexVerticalLine + 2] = 255;
294 int BigBowlLocalization::locateBowl(CByteImage** cameraImages,
Vec3d& bowlPosition, CByteImage** resultImages)
296 int numberOfSegments = 0;
303 ::ImageProcessor::CalculateHSVImage(
cameraImages[0], imageHSVLeft);
304 ::ImageProcessor::CalculateHSVImage(
cameraImages[1], imageHSVRight);
305 ::ImageProcessor::ConvertImage(
cameraImages[0], imgLeftGray);
306 ::ImageProcessor::ConvertImage(
cameraImages[1], imgRightGray);
307 ::ImageProcessor::Zero(imageFiltered);
309 int ThesholdHMinValue = 4;
310 int ThesholdHMaxValue = 20;
311 int ThesholdSMinValue = 220;
312 int ThesholdSMaxValue = 255;
314 int imagePosXLeft = 0;
315 int imagePosYLeft = 0;
316 int totalPixelLeft = 0;
317 int imagePosXRight = 0;
318 int imagePosYRight = 0;
319 int totalPixelRight = 0;
323 for (
int i = deltaROI; i < imageHSVLeft->width - deltaROI; i++)
325 for (
int j = deltaROI; j < imageHSVLeft->height - deltaROI; j++)
327 int pixelIndex = (i + j * imageHSVLeft->width) * imageHSVLeft->bytesPerPixel;
328 double hVal = (
double) imageHSVLeft->pixels[pixelIndex];
329 double sVal = (double) imageHSVLeft->pixels[pixelIndex + 1];
331 if ((hVal > ThesholdHMinValue && hVal < ThesholdHMaxValue) && (sVal > ThesholdSMinValue && sVal < ThesholdSMaxValue))
333 imageFiltered->pixels[pixelIndex] =
cameraImages[0]->pixels[pixelIndex];
334 imageFiltered->pixels[pixelIndex + 1] =
cameraImages[0]->pixels[pixelIndex + 1];
335 imageFiltered->pixels[pixelIndex + 2] =
cameraImages[0]->pixels[pixelIndex + 2];
342 ARMARX_INFO <<
"totalPixel >> left " << totalPixelLeft;
346 for (
int i = deltaROI; i < imageHSVRight->width - deltaROI; i++)
348 for (
int j = deltaROI; j < imageHSVRight->height - deltaROI; j++)
350 int pixelIndex = (i + j * imageHSVRight->width) * imageHSVRight->bytesPerPixel;
351 double hVal = (
double) imageHSVRight->pixels[pixelIndex];
352 double sVal = (double) imageHSVRight->pixels[pixelIndex + 1];
354 if ((hVal > ThesholdHMinValue && hVal < ThesholdHMaxValue) && (sVal > ThesholdSMinValue && sVal < ThesholdSMaxValue))
362 ARMARX_INFO <<
"totalPixel >> right " << totalPixelRight;
364 if (totalPixelLeft > 10000 && totalPixelRight > 10000)
366 numberOfSegments = 1;
372 ::ImageProcessor::Zero(imageFiltered);
374 numberOfSegments = 0;
375 return numberOfSegments;
378 Vec2d imageCoorLeft, imageCoorRight;
379 imageCoorLeft.x = (int) imagePosXLeft / totalPixelLeft;
380 imageCoorLeft.y = (int) imagePosYLeft / totalPixelLeft;
381 imageCoorRight.x = (int) imagePosXRight / totalPixelRight;
382 imageCoorRight.y = (int) imagePosYRight / totalPixelRight;
384 ARMARX_INFO <<
"imageCoorLeft x: " << imageCoorLeft.x <<
" y: " << imageCoorLeft.y;
385 ARMARX_INFO <<
"imageCoorRight x: " << imageCoorRight.x <<
" y: " << imageCoorRight.y;
387 if (imageCoorLeft.x < 250 || imageCoorLeft.x > 470 || imageCoorLeft.y < 150 || imageCoorLeft.y > 320)
391 ::ImageProcessor::Zero(imageFiltered);
393 numberOfSegments = 0;
394 return numberOfSegments;
397 Vec2d vCorrespondingPointRight;
398 const int nDispMin = stereoMatcher->GetDisparityEstimate(10000);
399 const int nDispMax = stereoMatcher->GetDisparityEstimate(500);
403 int nMatchingResult = stereoMatcher->Match(imgLeftGray, imgRightGray, (
int) imageCoorLeft.x, (
int) imageCoorLeft.y,
404 50, nDispMin, nDispMax, vCorrespondingPointRight, bowlPosition, 0.7f,
true);
407 ARMARX_INFO <<
"nMatchingResult " << nMatchingResult;
411 if (nMatchingResult <= 0)
415 ::ImageProcessor::Zero(imageFiltered);
417 numberOfSegments = 0;
418 return numberOfSegments;
422 int deltaCenter = 10;
423 for (
int i = imageCoorLeft.x - deltaCenter; i < imageCoorLeft.x + deltaCenter; i++)
425 for (
int j = imageCoorLeft.y - deltaCenter; j < imageCoorLeft.y + deltaCenter; j++)
427 int pixelIndex = (i + j * imageHSVLeft->width) * imageHSVLeft->bytesPerPixel;
428 imageFiltered->pixels[pixelIndex] = 255;
429 imageFiltered->pixels[pixelIndex + 1] = 255;
430 imageFiltered->pixels[pixelIndex + 2] = 255;
448 return numberOfSegments;