37 #include <Calibration/Calibration.h>
38 #include <Image/ByteImage.h>
39 #include <Math/Math3d.h>
43 const std::vector<CHypothesisPoint*>& aOldDepthMapPoints,
44 const std::vector<CHypothesisPoint*>& aNewDepthMapPoints,
45 const CByteImage* pForegroundImage,
46 const CByteImage* pHSVImage,
47 const CCalibration* calibration,
48 const Vec3d upwardsVector,
53 std::vector<CHypothesisPoint*> aForegroundPoints;
55 aNewDepthMapPoints, pForegroundImage, calibration, aForegroundPoints);
60 if (aForegroundPoints.size() > 0)
64 aOldDepthMapPoints, pForegroundImage, calibration, pObjectHypotheses);
71 for (
int i = 0; i < pObjectHypotheses->GetSize(); i++)
80 ARMARX_VERBOSE_S <<
"ValidateInitialHypothesis: Wrong hypothesis type (not RGBD or "
81 "SingleColored). Not checking it for motion.";
86 float fForegroundRatio;
87 int nForegroundPoints;
94 if (fForegroundRatio >
98 << (*pObjectHypotheses)[i]->nHypothesisNumber <<
" ("
99 << 100 * fForegroundRatio <<
" % change, "
100 << (*pObjectHypotheses)[i]->aNewPoints.size() <<
" points).";
110 (*pObjectHypotheses)[i],
111 pConfirmedHypothesis,
117 pConfirmedHypotheses->AddElement(pConfirmedHypothesis);
123 <<
" did not change (" << 100 * fForegroundRatio <<
" %).";
128 delete pPointCloudRegistration;
138 const std::vector<CHypothesisPoint*>& aNewDepthMapPoints,
139 const CByteImage* pForegroundImage,
140 const CByteImage* pHSVImage,
141 const CCalibration* calibration,
142 const Vec3d upwardsVector,
146 std::vector<CHypothesisPoint*> aForegroundPoints;
148 aNewDepthMapPoints, pForegroundImage, calibration, aForegroundPoints);
153 if (aForegroundPoints.size() > 0)
160 for (
int i = 0; i < pObjectHypotheses->GetSize(); i++)
166 << (*pObjectHypotheses)[i]->aConfirmedPoints.size() <<
" + "
167 << (*pObjectHypotheses)[i]->aNewPoints.size() <<
" points).";
177 pConfirmedHypothesis);
181 (*pObjectHypotheses)[i] = pConfirmedHypothesis;
182 delete pObjectHypothesis;
190 delete pPointCloudRegistration;
200 const std::vector<CHypothesisPoint*>& aOldDepthMapPoints,
201 const CByteImage* pForegroundImage,
202 const CCalibration* calibration,
205 std::vector<CHypothesisPoint*> aForegroundPointsFromOldPoints;
207 aOldDepthMapPoints, pForegroundImage, calibration, aForegroundPointsFromOldPoints);
209 <<
" points for foreground hypotheses";
212 std::vector<std::vector<CHypothesisPoint*>> aForegroundPointsFromOldPointsClusters;
217 aForegroundPointsFromOldPointsClusters);
218 ARMARX_VERBOSE_S << aForegroundPointsFromOldPointsClusters.size() <<
" foreground hypotheses";
220 for (
size_t i = 0; i < aForegroundPointsFromOldPointsClusters.size(); i++)
227 Vec3d vCenter = {0, 0, 0};
229 for (
size_t j = 0; j < aForegroundPointsFromOldPointsClusters.at(i).size(); j++)
232 aForegroundPointsFromOldPointsClusters.at(i).at(j)->GetCopy());
233 Math3d::AddToVec(vCenter,
234 aForegroundPointsFromOldPointsClusters.at(i).at(j)->vPosition);
237 Math3d::MulVecScalar(vCenter,
238 1.0 / aForegroundPointsFromOldPointsClusters.at(i).size(),
242 pObjectHypotheses->AddElement(pForegroundHypo);
250 const std::vector<CHypothesisPoint*>& aNewDepthMapPoints,
251 const std::vector<CHypothesisPoint*>& aForegroundPoints,
252 const CByteImage* pForegroundImage,
253 const CByteImage* pHSVImage,
254 const CCalibration* calibration,
255 const Vec3d upwardsVector,
258 const int nEffortLevel)
260 Mat3d mRot = Math3d::unit_mat;
261 Vec3d vTrans = Math3d::zero_vec;
262 float errorAtOriginalPosition = FLT_MAX;
266 pObjectHypothesis, errorAtOriginalPosition, nEffortLevel))
268 ARMARX_VERBOSE_S <<
"CHypothesisValidationRGBD: Initial check at old object position: the "
269 "transformation shows no motion.";
275 std::vector<Vec3d> aPossibleLocations;
284 std::vector<float> aPointMatchDistances;
285 std::vector<CColorICP::CPointXYZRGBI> aNearestNeighbors;
293 &aPointMatchDistances,
294 2 * errorAtOriginalPosition);
300 float fRotationAngle;
302 Math3d::GetAxisAndAngle(mRot, vTemp, fRotationAngle);
303 fRotationAngle *= 180.0f /
M_PI;
306 Math3d::MulMatVec(mRot, pObjectHypothesis->
vCenter, vTrans, vTemp);
307 float fDistance = Math3d::Distance(vTemp, pObjectHypothesis->
vCenter);
310 float fMotionMeasure = 2 * fRotationAngle + fDistance;
311 ARMARX_VERBOSE_S <<
"Motion measure: " << fMotionMeasure <<
" (" << fDistance <<
"mm, "
312 << fRotationAngle <<
"deg)";
318 int nNoForeground = 0;
319 int nLargeDistance = 0;
325 pTransformedHypo->
eType = pObjectHypothesis->
eType;
332 for (
size_t j = 0; j < pObjectHypothesis->
aNewPoints.size(); j++)
334 pPoint = pObjectHypothesis->
aNewPoints.at(j)->GetCopy();
337 bool bIsInForeground =
346 if (aPointMatchDistances.at(pObjectHypothesis->
aConfirmedPoints.size() + j) <
371 bool bIsInForeground =
396 pTransformedHypo->
aNewPoints.push_back(pPoint);
421 bool bIsInForeground =
450 ARMARX_VERBOSE_S <<
"Discarded features: no foreground " << nNoForeground <<
", bad match "
461 std::vector<Vec2d> aPointPositions2D;
466 calibration->WorldToImageCoordinates(
468 aPointPositions2D.at(i),
474 const Vec2d vPos2D = aPointPositions2D.at(i);
478 if (Math2d::Distance(vPos2D, aPointPositions2D.at(j)) <
491 aPointPositions2D.at(j) =
492 aPointPositions2D.at(aPointPositions2D.size() - 1);
499 <<
" points because they were too close to another one";
504 std::vector<CHypothesisPoint*> aNewCandidatePoints;
505 std::vector<Vec2d> aForegroundPoints2D, aConfirmedPoints2D, aNewAndDoubtablePoints2D;
506 std::vector<Vec3d> aForegroundPoints3D, aConfirmedPoints3D;
511 for (
size_t i = 0; i < aForegroundPoints.size(); i++)
513 Vec3d point3D = aForegroundPoints.at(i)->vPosition;
514 aForegroundPoints3D.push_back(point3D);
516 calibration->WorldToImageCoordinates(point3D, point2D,
false);
517 aForegroundPoints2D.push_back(point2D);
526 aConfirmedPoints3D.push_back(point3D);
528 calibration->WorldToImageCoordinates(point3D, point2D,
false);
529 aConfirmedPoints2D.push_back(point2D);
538 calibration->WorldToImageCoordinates(
540 aNewAndDoubtablePoints2D.push_back(point2D);
543 for (
size_t i = 0; i < pTransformedHypo->
aNewPoints.size(); i++)
546 calibration->WorldToImageCoordinates(
547 pTransformedHypo->
aNewPoints.at(i)->vPosition, point2D,
false);
548 aNewAndDoubtablePoints2D.push_back(point2D);
555 Math3d::Transpose(mRot, mRotInv);
559 #pragma omp parallel for
560 for (
size_t j = 0; j < aForegroundPoints.size(); j++)
563 Vec3d vOldPointPosition;
564 Math3d::SubtractVecVec(aForegroundPoints.at(j)->vPosition, vTrans, vTemp);
565 Math3d::MulMatVec(mRotInv, vTemp, vOldPointPosition);
568 vOldPointPosition, pForegroundImage, calibration))
571 Vec2d vPos2D = aForegroundPoints2D.at(j);
572 Vec3d vPos3D = aForegroundPoints3D.at(j);
573 float fDist2D, fDist3D;
574 float fMinDist2D = FLT_MAX;
575 float fMinDist3D = FLT_MAX;
577 for (
size_t k = 0; k < aConfirmedPoints2D.size(); k++)
579 fDist2D = Math2d::Distance(vPos2D, aConfirmedPoints2D.at(k));
581 if (fDist2D < fMinDist2D)
583 fMinDist2D = fDist2D;
586 fDist3D = Math3d::Distance(vPos3D, aConfirmedPoints3D.at(k));
588 if (fDist3D < fMinDist3D)
590 fMinDist3D = fDist3D;
596 (fMinDist2D > fMinDistanceLimit2D))
598 for (
size_t k = 0; k < aNewAndDoubtablePoints2D.size(); k++)
600 fDist2D = Math2d::Distance(vPos2D, aNewAndDoubtablePoints2D.at(k));
602 if (fDist2D < fMinDist2D)
604 fMinDist2D = fDist2D;
608 if (fMinDist2D > fMinDistanceLimit2D)
612 aNewCandidatePoints.push_back(aForegroundPoints.at(j)->GetCopy());
619 for (
size_t i = 0; i < aNewCandidatePoints.size(); i++)
634 pTransformedHypo->
aNewPoints.push_back(aNewCandidatePoints.at(i));
650 #ifdef OLP_ADD_POINTS_FROM_SEGMENTED_REGION
651 CByteImage* pSegmentationMask = NULL;
653 pTransformedHypo, calibration, pSegmentationMask);
660 i < pTransformedHypo->aConfirmedPoints.size();
670 Vec3d vNewCenter = {0, 0, 0};
696 Math3d::Distance(pTransformedHypo->
vCenter,
707 pConfirmedHypothesis = pTransformedHypo;
715 <<
"CHypothesisValidationRGBD: not enough points left after transformation";
716 delete pTransformedHypo;
723 ARMARX_VERBOSE_S <<
"CHypothesisValidationRGBD: the transformation shows no motion.";