25 #include "../../../vision_algorithms/HandLocalizationWithFingertips/HandLocalisation.h"
26 #include "../../../vision_algorithms/HandLocalizationWithFingertips/Visualization/HandModelVisualizer.h"
27 #include "Helpers/helpers.h"
33 #include <Calibration/StereoCalibration.h>
34 #include <Image/ImageProcessor.h>
35 #include <Math/Math3d.h>
50 RobotHandLocalizationWithFingertips::onInitImageProcessor()
53 providerName = getProperty<std::string>(
"ImageProviderAdapterName").getValue();
54 usingImageProvider(providerName);
56 robotStateProxyName = getProperty<std::string>(
"RobotStateProxyName").getValue();
57 usingProxy(robotStateProxyName);
59 handFrameName = getProperty<std::string>(
"HandFrameName").getValue();
60 cameraFrameName = getProperty<std::string>(
"CameraFrameName").getValue();
64 RobotHandLocalizationWithFingertips::onConnectImageProcessor()
69 imageProviderPrx = getProxy<ImageProviderInterfacePrx>(providerName);
72 cameraImages =
new CByteImage*[2];
76 resultImages =
new CByteImage*[numResultImages];
78 for (
int i = 0; i < numResultImages; i++)
84 StereoCalibrationProviderInterfacePrx calibrationProviderPrx =
85 StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderPrx);
87 if (!calibrationProviderPrx)
89 ARMARX_ERROR <<
"Image provider with name " << providerName
90 <<
" is not a StereoCalibrationProvider" << std::endl;
99 robotStateProxy = getProxy<RobotStateComponentInterfacePrx>(robotStateProxyName);
101 this->enableResultImages(numResultImages, imageFormat.dimension, imageFormat.type);
110 RobotHandLocalizationWithFingertips::process()
112 if (!waitForImages(8000))
119 int nNumberImages = getImages(cameraImages);
120 ARMARX_VERBOSE << getName() <<
" got " << nNumberImages <<
" images";
124 armarx::PosePtr::dynamicCast(robotStateProxy->getSynchronizedRobot()
125 ->getRobotNode(handFrameName)
126 ->getPoseInRootFrame());
129 armarx::PosePtr::dynamicCast(robotStateProxy->getSynchronizedRobot()
130 ->getRobotNode(cameraFrameName)
131 ->getPoseInRootFrame());
133 Eigen::Matrix4f handPoseInCameraFrame = cameraNodePose.inverse() * handNodePose;
134 Vec3d handNodePosition = {handPoseInCameraFrame(0, 3),
135 handPoseInCameraFrame(1, 3),
136 handPoseInCameraFrame(2, 3)};
137 Mat3d handNodeOrientation = {handPoseInCameraFrame(0, 0),
138 handPoseInCameraFrame(0, 1),
139 handPoseInCameraFrame(0, 2),
140 handPoseInCameraFrame(1, 0),
141 handPoseInCameraFrame(1, 1),
142 handPoseInCameraFrame(1, 2),
143 handPoseInCameraFrame(2, 0),
144 handPoseInCameraFrame(2, 1),
145 handPoseInCameraFrame(2, 2)};
149 double* fingerConfig =
new double[6];
150 fingerConfig[0] = 90 *
M_PI / 180;
151 fingerConfig[1] = 25 *
M_PI / 180;
152 fingerConfig[2] = 15 *
M_PI / 180;
153 fingerConfig[3] = 10 *
M_PI / 180;
154 fingerConfig[4] = 5 *
M_PI / 180;
155 fingerConfig[5] = 5 *
M_PI / 180;
159 double* estimatedConfig =
new double[12];
160 double confidenceRating;
161 handLocalization->LocaliseHand(cameraImages[0],
170 ::ImageProcessor::CopyImage(cameraImages[0], resultImages[0]);
171 ::ImageProcessor::CopyImage(cameraImages[0], resultImages[1]);
172 ::ImageProcessor::CopyImage(cameraImages[0], resultImages[2]);
173 ::ImageProcessor::Zero(resultImages[3]);
175 double* localizationResult = handLocalization->GetResultConfig();
176 handModelVisualizer->UpdateHandModel(localizationResult,
177 drawComplexHandModelInResultImage);
178 delete[] localizationResult;
179 handModelVisualizer->DrawHandModelV2(resultImages[1]);
180 handModelVisualizer->DrawHand(resultImages[2]);
181 handModelVisualizer->DrawSegmentedImage(resultImages[3]);
182 provideResultImages(resultImages);
187 RobotHandLocalizationWithFingertips::onExitImageProcessor()
189 delete[] cameraImages;
192 armarx::FramedPoseBasePtr
193 RobotHandLocalizationWithFingertips::getHandPose(
const Ice::Current&
c)
197 handPose, cameraFrameName, robotStateProxy->getSynchronizedRobot()->getName());
201 visionx::FramedPositionBaseList
202 RobotHandLocalizationWithFingertips::getFingertipPositions(
const Ice::Current&
c)
204 visionx::FramedPositionBaseList
ret;
205 std::vector<Vec3d> fingertipPositions = handLocalization->GetFingertipPositions();
207 for (
size_t i = 0; i < fingertipPositions.size(); i++)
209 Eigen::Vector3f position;
210 position << fingertipPositions.at(i).x, fingertipPositions.at(i).y,
211 fingertipPositions.at(i).z;
213 position, cameraFrameName, robotStateProxy->getSynchronizedRobot()->getName());