30 #include "Image/ByteImage.h"
31 #include "Image/ImageProcessor.h"
32 #include "Image/IplImageAdaptor.h"
33 #include "Calibration/StereoCalibration.h"
34 #include "Calibration/Calibration.h"
37 #include <opencv2/opencv.hpp>
47 cameraImageProviderName = getProperty<std::string>(
"CameraImageProviderAdapterName").getValue();
50 kinectImageProviderName = getProperty<std::string>(
"KinectImageProviderAdapterName").getValue();
53 const int cornersPerRow = getProperty<int>(
"NumberOfRows").getValue() - 1;
54 const int cornersPerColumn = getProperty<int>(
"NumberOfColumns").getValue() - 1;
55 const double squareSize = getProperty<double>(
"PatternSquareSize").getValue();
57 waitingIntervalBetweenImages = getProperty<int>(
"WaitingIntervalBetweenImages").getValue();
58 m_sCameraParameterFileName = getProperty<std::string>(
"OutputFileName").getValue();
59 desiredNumberOfImages = getProperty<int>(
"NumberOfImages").getValue();
60 numberOfCapturedImages = 0;
64 ARMARX_INFO <<
"Calibration pattern with " << cornersPerColumn + 1 <<
" x " << cornersPerRow + 1 <<
" squares of size " << squareSize;
65 etalonParams[0] = double(cornersPerColumn + 1);
66 etalonParams[1] = double(cornersPerRow + 1);
67 etalonParams[2] = squareSize;
69 m_pCalibFilter->
SetFrames(desiredNumberOfImages);
80 cameraImageProviderPrx = getProxy<ImageProviderInterfacePrx>(cameraImageProviderName);
81 listenerPrx = getTopic<KinectAndCameraCalibrationListenerPrx>(
"KinectAndCameraCalibration");
83 cameraImages =
new CByteImage*[2];
89 kinectImageProviderPrx = getProxy<ImageProviderInterfacePrx>(kinectImageProviderName);
90 kinectImages =
new CByteImage*[kinectImageProviderPrx->getNumberImages()];
92 for (
int i = 0; i < kinectImageProviderPrx->getNumberImages(); i++)
94 kinectImages[i] =
tools::createByteImage(kinectImageProviderPrx->getImageFormat(), kinectImageProviderPrx->getImageFormat().type);
97 startingTime = IceUtil::Time::now();
98 timeOfLastCapture = IceUtil::Time::now();
102 result.result =
false;
109 result.result =
false;
112 delete cameraImages[0];
113 delete cameraImages[1];
114 delete[] cameraImages;
115 delete m_pCalibFilter;
122 long timeSinceStart = (IceUtil::Time::now() - startingTime).toMilliSeconds();
124 if (timeSinceStart < 10000)
126 ARMARX_VERBOSE <<
"Time until start of capture: " << timeSinceStart - 10000 <<
" ms";
132 armarx::MetaInfoSizeBasePtr info;
133 int nNumberCameraImages =
getImages(cameraImageProviderName, cameraImages, info);
136 armarx::MetaInfoSizeBasePtr info2;
137 int nNumberKinectImages =
getImages(kinectImageProviderName, kinectImages, info2);
140 if (nNumberCameraImages > 0 && nNumberKinectImages > 0)
142 if ((IceUtil::Time::now() - timeOfLastCapture).toMilliSeconds() > waitingIntervalBetweenImages)
144 ARMARX_INFO <<
"Capturing image " << numberOfCapturedImages + 1 <<
" of " << desiredNumberOfImages;
145 IplImage* ppIplImages[2] = { IplImageAdaptor::Adapt(cameraImages[0]), IplImageAdaptor::Adapt(kinectImages[0]) };
150 numberOfCapturedImages++;
151 timeOfLastCapture = IceUtil::Time::now();
153 m_pCalibFilter->
Push();
155 if (numberOfCapturedImages == desiredNumberOfImages)
162 ARMARX_INFO <<
"Saving camera calibration to file " << m_sCameraParameterFileName;
164 CStereoCalibration calibration;
165 calibration.LoadCameraParameters(m_sCameraParameterFileName.c_str());
166 CCalibration cRight = *calibration.GetRightCalibration();
167 Vec3d translation = cRight.GetCameraParameters().translation;
168 ARMARX_INFO <<
"RightCalibration traslation; " << translation.x <<
" " << translation.y <<
" " << translation.z;
169 Mat3d rotation = cRight.GetCameraParameters().rotation;
171 << rotation.r1 <<
" " << rotation.r2 <<
" " << rotation.r3 <<
" \n"
172 << rotation.r4 <<
" " << rotation.r5 <<
" " << rotation.r6 <<
" \n"
173 << rotation.r7 <<
" " << rotation.r8 <<
" " << rotation.r9 <<
" \n";
176 CCalibration cLeft = *calibration.GetLeftCalibration();
177 Vec3d translationLeft = cLeft.GetCameraParameters().translation;
178 ARMARX_INFO <<
"LeftCalibration traslation; " << translationLeft.x <<
" " << translationLeft.y <<
" " << translationLeft.z;
179 Mat3d rotationLeft = cLeft.GetCameraParameters().rotation;
181 << rotationLeft.r1 <<
" " << rotationLeft.r2 <<
" " << rotationLeft.r3 <<
" \n"
182 << rotationLeft.r4 <<
" " << rotationLeft.r5 <<
" " << rotationLeft.r6 <<
" \n"
183 << rotationLeft.r7 <<
" " << rotationLeft.r8 <<
" " << rotationLeft.r9 <<
" \n";
186 result.result = finished;
189 listenerPrx->reportCalibrationFinished(result.result);
209 startingTime = IceUtil::Time::now();
217 startingTime = IceUtil::Time::now();
225 numberOfCapturedImages = 0;
226 delete m_pCalibFilter;
229 m_pCalibFilter->
SetFrames(desiredNumberOfImages);
233 result.result =
false;
235 startingTime = IceUtil::Time::now();