24 #include "Helpers/helpers.h"
25 #include "../../../vision_algorithms/HandLocalizationWithFingertips/HandLocalisation.h"
26 #include "../../../vision_algorithms/HandLocalizationWithFingertips/Visualization/HandModelVisualizer.h"
32 #include <Calibration/StereoCalibration.h>
33 #include <Math/Math3d.h>
34 #include <Image/ImageProcessor.h>
49 void RobotHandLocalizationWithFingertips::onInitImageProcessor()
52 providerName = getProperty<std::string>(
"ImageProviderAdapterName").getValue();
53 usingImageProvider(providerName);
55 robotStateProxyName = getProperty<std::string>(
"RobotStateProxyName").getValue();
56 usingProxy(robotStateProxyName);
58 handFrameName = getProperty<std::string>(
"HandFrameName").getValue();
59 cameraFrameName = getProperty<std::string>(
"CameraFrameName").getValue();
62 void RobotHandLocalizationWithFingertips::onConnectImageProcessor()
67 imageProviderPrx = getProxy<ImageProviderInterfacePrx>(providerName);
70 cameraImages =
new CByteImage*[2];
74 resultImages =
new CByteImage*[numResultImages];
76 for (
int i = 0; i < numResultImages; i++)
82 StereoCalibrationProviderInterfacePrx calibrationProviderPrx = StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderPrx);
84 if (!calibrationProviderPrx)
86 ARMARX_ERROR <<
"Image provider with name " << providerName <<
" is not a StereoCalibrationProvider" << std::endl;
95 robotStateProxy = getProxy<RobotStateComponentInterfacePrx>(robotStateProxyName);
97 this->enableResultImages(numResultImages, imageFormat.dimension, imageFormat.type);
104 void RobotHandLocalizationWithFingertips::process()
106 if (!waitForImages(8000))
113 int nNumberImages = getImages(cameraImages);
114 ARMARX_VERBOSE << getName() <<
" got " << nNumberImages <<
" images";
117 armarx::PosePtr handNodePosePtr = armarx::PosePtr::dynamicCast(robotStateProxy->getSynchronizedRobot()->getRobotNode(handFrameName)->getPoseInRootFrame());
119 armarx::PosePtr cameraNodePosePtr = armarx::PosePtr::dynamicCast(robotStateProxy->getSynchronizedRobot()->getRobotNode(cameraFrameName)->getPoseInRootFrame());
121 Eigen::Matrix4f handPoseInCameraFrame = cameraNodePose.inverse() * handNodePose;
122 Vec3d handNodePosition = {handPoseInCameraFrame(0, 3), handPoseInCameraFrame(1, 3), handPoseInCameraFrame(2, 3)};
123 Mat3d handNodeOrientation = {handPoseInCameraFrame(0, 0), handPoseInCameraFrame(0, 1), handPoseInCameraFrame(0, 2),
124 handPoseInCameraFrame(1, 0), handPoseInCameraFrame(1, 1), handPoseInCameraFrame(1, 2),
125 handPoseInCameraFrame(2, 0), handPoseInCameraFrame(2, 1), handPoseInCameraFrame(2, 2)
130 double* fingerConfig =
new double[6];
131 fingerConfig[0] = 90 *
M_PI / 180;
132 fingerConfig[1] = 25 *
M_PI / 180;
133 fingerConfig[2] = 15 *
M_PI / 180;
134 fingerConfig[3] = 10 *
M_PI / 180;
135 fingerConfig[4] = 5 *
M_PI / 180;
136 fingerConfig[5] = 5 *
M_PI / 180;
140 double* estimatedConfig =
new double[12];
141 double confidenceRating;
142 handLocalization->LocaliseHand(cameraImages[0], cameraImages[1], handNodePosition, handNodeOrientation, fingerConfig, estimatedConfig, confidenceRating);
145 ::ImageProcessor::CopyImage(cameraImages[0], resultImages[0]);
146 ::ImageProcessor::CopyImage(cameraImages[0], resultImages[1]);
147 ::ImageProcessor::CopyImage(cameraImages[0], resultImages[2]);
148 ::ImageProcessor::Zero(resultImages[3]);
150 double* localizationResult = handLocalization->GetResultConfig();
151 handModelVisualizer->UpdateHandModel(localizationResult, drawComplexHandModelInResultImage);
152 delete[] localizationResult;
153 handModelVisualizer->DrawHandModelV2(resultImages[1]);
154 handModelVisualizer->DrawHand(resultImages[2]);
155 handModelVisualizer->DrawSegmentedImage(resultImages[3]);
156 provideResultImages(resultImages);
164 void RobotHandLocalizationWithFingertips::onExitImageProcessor()
166 delete [] cameraImages;
171 armarx::FramedPoseBasePtr RobotHandLocalizationWithFingertips::getHandPose(
const Ice::Current&
c)
180 visionx::FramedPositionBaseList RobotHandLocalizationWithFingertips::getFingertipPositions(
const Ice::Current&
c)
182 visionx::FramedPositionBaseList
ret;
183 std::vector<Vec3d> fingertipPositions = handLocalization->GetFingertipPositions();
185 for (
size_t i = 0; i < fingertipPositions.size(); i++)
187 Eigen::Vector3f position;
188 position << fingertipPositions.at(i).x, fingertipPositions.at(i).y, fingertipPositions.at(i).z;