26 #include <Image/ImageProcessor.h>
50 m_fFocalLengthX = pCalibration->GetLeftCalibration()->GetCameraParameters().focalLength.x;
51 m_fFocalLengthY = pCalibration->GetLeftCalibration()->GetCameraParameters().focalLength.y;
52 m_fPrincipalPointX = pCalibration->GetLeftCalibration()->GetCameraParameters().principalPoint.x;
53 m_fPrincipalPointY = pCalibration->GetLeftCalibration()->GetCameraParameters().principalPoint.y;
57 m_fFocalLengthX = pCalibration->GetRightCalibration()->GetCameraParameters().focalLength.x;
58 m_fFocalLengthY = pCalibration->GetRightCalibration()->GetCameraParameters().focalLength.y;
59 m_fPrincipalPointX = pCalibration->GetRightCalibration()->GetCameraParameters().principalPoint.x;
60 m_fPrincipalPointY = pCalibration->GetRightCalibration()->GetCameraParameters().principalPoint.y;
94 if (bUpdateOpenInventorModel)
180 if (bDrawCylinderInHand)
182 printf(
"Warning: CHandModelVisualizer::ConfigureMoveMasterModel: Cylinder not available with new HandmodelV2. Code needs to be changed.\n");
185 Vec3d vCylinderCenter = {0, 0, -1000};
193 vConfPos.x = pConfig[0];
194 vConfPos.y = pConfig[1];
195 vConfPos.z = pConfig[2];
199 Mat3d m0, m1, m2, m3;
201 Math3d::SetRotationMat(m0, pConfig[3], pConfig[4], pConfig[5]);
202 Math3d::SetRotationMatX(m1, -
M_PI / 2);
203 Math3d::SetRotationMatZ(m2,
M_PI / 2);
204 Math3d::MulMatMat(m1, m2, m3);
205 Math3d::MulMatMat(m0, m3, m1);
246 const int width = pImage->width;
247 int leftBorderInt, rightBorderInt, up, down, indexLeft, indexRight, indexMain, nTempOffset;
248 float leftBorder = 0, rightBorder = 0, leftOffset = 0, rightOffset = 0;
252 for (indexMain = 0; indexMain < pPolygon.
nCorners - 1; indexMain++)
254 if (pPolygon.
hull[indexMain].z != 2)
256 leftBorder = pPolygon.
hullLeft[indexLeft].x;
259 if (pPolygon.
hull[indexMain].z != 1)
261 rightBorder = pPolygon.
hullRight[indexRight].x;
264 up = (int) pPolygon.
hull[indexMain].y;
265 down = (
int) pPolygon.
hull[indexMain + 1].y;
267 if (pPolygon.
hull[indexMain + 1].z != 2)
271 if (pPolygon.
hull[indexMain + 1].z != 1)
291 for (
int j = up; j > down; j--, leftBorder -= leftOffset, rightBorder -= rightOffset)
294 leftBorderInt = (int)leftBorder;
295 rightBorderInt = (int)rightBorder;
303 if (leftBorderInt < 0)
312 nTempOffset = j * width;
313 for (
int k = leftBorderInt; k < rightBorderInt; k++)
315 pImage->pixels[3 * (nTempOffset + k) + 0] = 0;
316 pImage->pixels[3 * (nTempOffset + k) + 1] = 0;
317 pImage->pixels[3 * (nTempOffset + k) + 2] = 255;
331 const int width = pImage->width;
332 int leftBorderInt, rightBorderInt, up, down, indexLeft, indexRight, indexMain, nTempOffset;
333 float leftBorder = 0, rightBorder = 0, leftOffset = 0, rightOffset = 0;
337 for (indexMain = 0; indexMain < pPolygon.
nCorners - 1; indexMain++)
339 if (pPolygon.
hull[indexMain].z != 2)
341 leftBorder = pPolygon.
hullLeft[indexLeft].x;
344 if (pPolygon.
hull[indexMain].z != 1)
346 rightBorder = pPolygon.
hullRight[indexRight].x;
349 up = (int) pPolygon.
hull[indexMain].y;
350 down = (
int) pPolygon.
hull[indexMain + 1].y;
352 if (pPolygon.
hull[indexMain + 1].z != 2)
356 if (pPolygon.
hull[indexMain + 1].z != 1)
376 for (
int j = up; j > down; j--, leftBorder -= leftOffset, rightBorder -= rightOffset)
379 leftBorderInt = (int)leftBorder;
380 rightBorderInt = (int)rightBorder;
388 if (leftBorderInt < 0)
397 nTempOffset = j * width;
398 for (
int k = leftBorderInt; k < rightBorderInt; k++)
400 pImage->pixels[nTempOffset + k] = 255;
495 if (bLeftCameraImage)
497 for (
int i = 0; i < 5; i++)
504 for (
int i = 0; i < 5; i++)
513 Vec2d vProjectedPoint1, vProjectedPoint2;
518 for (
int i = 0; i < 5; i++)
521 DrawLineIntoImage(pImage, vProjectedPoint1.x, vProjectedPoint1.y, vProjectedPoint2.x, vProjectedPoint2.y, 50 * i, 50 * i, 255 - 50 * i);
525 for (
int i = 0; i < 5; i++)
531 DrawLineIntoImage(pImage, vProjectedPoint1.x, vProjectedPoint1.y, vProjectedPoint2.x, vProjectedPoint2.y, 50 * j, 255 - 50 * i, 50 * i);
532 Math2d::SetVec(vProjectedPoint1, vProjectedPoint2);
538 double dCenterX, dCenterY, dRadius;
539 if (bLeftCameraImage)
552 int up = (int)(dCenterY - dRadius);
553 int down = (int)(dCenterY + dRadius);
554 for (
int i = up; i <= down; i++)
556 int leftBorderInt = (int)(dCenterX -
sqrt(dRadius * dRadius - (i - dCenterY) * (i - dCenterY)));
557 int rightBorderInt = (int)(dCenterX +
sqrt(dRadius * dRadius - (i - dCenterY) * (i - dCenterY)));
558 for (
int j = leftBorderInt; j <= rightBorderInt; j++)
576 int tempIndex, tempIndexX, tempIndexY;
586 for (
int i = 0; i < renderSizeY; i++)
588 for (
int j = 0; j < renderSizeX; j++)
591 if (pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j)] < 255 || pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 1] > 0 || pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 2] > 0)
593 tempIndexX = j - (renderSizeX / 2) + principal_point_x;
594 tempIndexY = i - (renderSizeY / 2) + principal_point_y;
601 pImage->pixels[tempIndex + 0] = 0.4 * pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 0] + 0.6 * pImage->pixels[tempIndex + 0];
602 pImage->pixels[tempIndex + 1] = 0.4 * pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 1] + 0.6 * pImage->pixels[tempIndex + 1];
603 pImage->pixels[tempIndex + 2] = 0.4 * pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 2] + 0.6 * pImage->pixels[tempIndex + 2];
617 if (!bUseOpenInventorModel)
633 ::ImageProcessor::Zero(pImage);
637 int tempIndex, tempIndexX, tempIndexY;
641 for (
int i = 0; i < renderSizeY; i++)
643 for (
int j = 0; j < renderSizeX; j++)
646 if (pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j)] < 250 || pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 1] > 10 || pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 2] > 10)
648 tempIndexX = j - (renderSizeX / 2) + principal_point_x;
649 tempIndexY = i - (renderSizeY / 2) + principal_point_y;
657 if (pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j)] > 250 && pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 1] > 250 && pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 2] < 10)
659 pImage->pixels[tempIndex] = 42;
662 else if (pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j)] < 10 && pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 1] > 250 && pRenderedImage[3 * (renderSizeX * (renderSizeY - i) + j) + 2] > 250)
664 pImage->pixels[tempIndex] = 128;
669 pImage->pixels[tempIndex] = 255;
677 if (pImage->type == CByteImage::eRGB24)
681 pImage->pixels[3 * i] = pImage->pixels[i];
685 pImage->pixels[3 * i + 1] = pImage->pixels[3 * i];
686 pImage->pixels[3 * i + 2] = pImage->pixels[3 * i];
699 if (pSegmentedImage->type == CByteImage::eRGB24)
701 pImage =
new CByteImage(pSegmentedImage->width, pSegmentedImage->height, CByteImage::eGrayScale);
705 pImage = pSegmentedImage;
707 ::ImageProcessor::Zero(pImage);
710 for (
int i = 0; i < 5; i++)
715 const float fFingerWidth = 25.0f;
718 for (
int i = 0; i < 5; i++)
724 for (
int i = 0; i < 5; i++)
733 double dCenterX, dCenterY, dRadius;
738 int up = (int)(dCenterY - dRadius);
739 int down = (int)(dCenterY + dRadius);
740 for (
int i = up; i <= down; i++)
742 int leftBorderInt = (int)(dCenterX -
sqrt(dRadius * dRadius - (i - dCenterY) * (i - dCenterY)));
743 int rightBorderInt = (int)(dCenterX +
sqrt(dRadius * dRadius - (i - dCenterY) * (i - dCenterY)));
744 for (
int j = leftBorderInt; j <= rightBorderInt; j++)
754 Vec3d vArmLength = {0, 0, -500};
759 CByteImage* pTempImage =
new CByteImage(pImage);
763 ::ImageProcessor::Dilate(pImage, pTempImage, 14);
764 ::ImageProcessor::Dilate(pTempImage, pImage, 14);
771 if (pSegmentedImage->type == CByteImage::eRGB24)
773 for (
int i = 0; i < pSegmentedImage->width * pSegmentedImage->height; i++)
775 pSegmentedImage->pixels[3 * i + 0] = pImage->pixels[i];
776 pSegmentedImage->pixels[3 * i + 1] = pImage->pixels[i];
777 pSegmentedImage->pixels[3 * i + 2] = pImage->pixels[i];
789 for (
int j = -3; j <= 3; j++)
802 for (
int j = -3; j <= 3; j++)
820 if (x1 < 0 || x1 >= pImage->width || x2 < 0 || x2 >= pImage->width || y1 < 0 || y1 >= pImage->height || y2 < 0 || y2 >= pImage->height)
825 if (x1 == x2 && y1 == y2)
827 pImage->pixels[3 * (y1 * pImage->width + x1)] =
red;
828 pImage->pixels[3 * (y1 * pImage->width + x1) + 1] =
green;
829 pImage->pixels[3 * (y1 * pImage->width + x1) + 2] = blue;
845 float divided_diff = (
float)(y2 - y1) / (
float)(x2 - x1);
847 for (
int i = x1; i < x2; i++)
849 pImage->pixels[3 * (((int)((i - x1)*divided_diff) + y1) * pImage->width + i)] =
red;
850 pImage->pixels[3 * (((int)((i - x1)*divided_diff) + y1) * pImage->width + i) + 1] =
green;
851 pImage->pixels[3 * (((int)((i - x1)*divided_diff) + y1) * pImage->width + i) + 2] = blue;
866 divided_diff = (
float)(x2 - x1) / (
float)(y2 - y1);
868 for (
int i = y1; i < y2; i++)
870 pImage->pixels[3 * (i * pImage->width + x1 + (int)((i - y1)*divided_diff))] =
red;
871 pImage->pixels[3 * (i * pImage->width + x1 + (int)((i - y1)*divided_diff)) + 1] =
green;
872 pImage->pixels[3 * (i * pImage->width + x1 + (int)((i - y1)*divided_diff)) + 2] = blue;
882 Math3d::SubtractVecVec(vEnd, vStart, vDirection);
883 Vec3d vOrthogonalXY = {-vDirection.y, vDirection.x, 0};
884 if (Math3d::Length(vOrthogonalXY) == 0)
888 Math3d::NormalizeVec(vOrthogonalXY);
889 Vec3d vOrthogonalStart, vOrthogonalEnd;
890 Math3d::MulVecScalar(vOrthogonalXY, 0.5f * fWidthAtStart, vOrthogonalStart);
891 Math3d::MulVecScalar(vOrthogonalXY, 0.5f * fWidthAtEnd, vOrthogonalEnd);
893 Vec3d p1, p2, p3, p4;
894 Math3d::AddVecVec(vStart, vOrthogonalStart, p1);
895 Math3d::SubtractVecVec(vStart, vOrthogonalStart, p2);
896 Math3d::AddVecVec(vEnd, vOrthogonalEnd, p3);
897 Math3d::SubtractVecVec(vEnd, vOrthogonalEnd, p4);
899 Vec2d vProjPoint1, vProjPoint2, vProjPoint3, vProjPoint4;
907 pPoints[0].x = vProjPoint1.x;
908 pPoints[0].y = vProjPoint1.y;
909 pPoints[1].x = vProjPoint2.x;
910 pPoints[1].y = vProjPoint2.y;
911 pPoints[2].x = vProjPoint3.x;
912 pPoints[2].y = vProjPoint3.y;
913 pPoints[3].x = vProjPoint4.x;
914 pPoints[3].y = vProjPoint4.y;
929 if (pImage->type == CByteImage::eGrayScale)
943 angles.y = asin(mat.r3);
944 angles.x = atan2((-mat.r6), (mat.r9));
945 angles.z = atan2((-mat.r2), (mat.r1));