27 #include <Ice/Properties.h>
43 #include <Calibration/Calibration.h>
49 void ImageSequenceProvider::onInitCapturingImageProvider()
52 filePathLeft = getProperty<std::string>(
"PathLeft").getValue();
55 filePathRight = getProperty<std::string>(
"PathRight").getValue();
58 setImageFormat(visionx::ImageDimension(getProperty<ImageDimension>(
"ImageSize").getValue()), visionx::eRgb);
59 setImageSyncMode(eFpsSynchronization);
60 frameRate = getProperty<float>(
"FrameRate").getValue();
63 bitmapSequenceCapture = NULL;
66 loadNewImageAtNextCapture =
true;
69 std::string calibrationFileName = getProperty<std::string>(
"CalibrationFile").getValue();
70 if (!calibrationFileName.empty())
72 std::string fullCalibrationFileName;
76 ARMARX_ERROR <<
"Could not find camera calibration file in ArmarXDataPath: " << calibrationFileName;
79 if (!ivtStereoCalibration.LoadCameraParameters(
80 fullCalibrationFileName.c_str(),
true))
82 ARMARX_ERROR <<
"Error loading camera calibration file: " << fullCalibrationFileName;
88 repeatImageCount = getProperty<int>(
"RepeatImageCount");
92 void ImageSequenceProvider::onExitCapturingImageProvider()
96 for (
int i = 0; i < getNumberImages(); i++)
99 delete resizedImages[i];
103 delete [] resizedImages;
110 void ImageSequenceProvider::onStartCapture(
float frameRate)
112 if (!bitmapSequenceCapture->OpenCamera())
115 "Opening bitmap sequence \"" + filePathLeft +
"\" failed.");
119 loadNewImageAtNextCapture =
true;
120 currentRepeatCount = repeatImageCount - 1;
125 void ImageSequenceProvider::onStopCapture()
127 bitmapSequenceCapture->CloseCamera();
131 bool ImageSequenceProvider::capture(
void** ppImageBuffers)
133 bool succeeded =
true;
135 if (loadNewImageAtNextCapture)
137 std::unique_lock lock(captureMutex);
141 loadNewImageAtNextCapture = getProperty<bool>(
"LoadNextImageAutomatically").getValue();
143 ++currentRepeatCount;
144 if (currentRepeatCount == repeatImageCount)
146 succeeded = bitmapSequenceCapture->CaptureImage(images);
147 currentRepeatCount = 0;
151 bitmapSequenceCapture->Rewind();
152 succeeded = bitmapSequenceCapture->CaptureImage(images);
161 for (
int i = 0; i < getNumberImages(); i++)
163 ::ImageProcessor::Resize(images[i], resizedImages[i]);
165 memcpy(ppImageBuffers[i], resizedImages[i]->pixels,
166 getImageFormat().dimension.width * getImageFormat().dimension.height * getImageFormat().bytesPerPixel);
176 StereoCalibration ImageSequenceProvider::getStereoCalibration(
const Ice::Current&
c)
178 return stereoCalibration;
182 bool ImageSequenceProvider::getImagesAreUndistorted(
const Ice::Current&
c)
184 return getProperty<bool>(
"ImagesAreUndistorted").getValue();
188 void ImageSequenceProvider::setImageFilePath(
const std::string& imageFilePathLeft,
const std::string& imageFilePathRight,
const Ice::Current&
c)
190 filePathLeft = imageFilePathLeft;
191 filePathRight = imageFilePathRight;
197 void ImageSequenceProvider::OpenImageFiles()
199 std::unique_lock lock(captureMutex);
201 bool isStereoMode = filePathRight.length() > 0;
203 std::string fullFilePathLeft, fullFilePathRight;
207 ARMARX_ERROR <<
"Could not find left image sequence file in ArmarXDataPath: " << filePathLeft;
212 ARMARX_ERROR <<
"Could not find right image sequence file in ArmarXDataPath: " << filePathRight;
215 if (bitmapSequenceCapture)
217 delete bitmapSequenceCapture;
220 bitmapSequenceCapture =
new CBitmapSequenceCapture(fullFilePathLeft.c_str(), (isStereoMode ? fullFilePathRight.c_str() : NULL));
226 if (bitmapSequenceCapture->OpenCamera())
228 width = bitmapSequenceCapture->GetWidth();
229 height = bitmapSequenceCapture->GetHeight();
231 loadNewImageAtNextCapture =
true;
241 for (
int i = 0; i < getNumberImages(); i++)
244 delete resizedImages[i];
248 delete [] resizedImages;
252 setNumberImages((isStereoMode ? 2 : 1));
255 images =
new CByteImage*[getNumberImages()];
257 for (
int i = 0; i < getNumberImages(); i++)
259 images[i] =
new CByteImage(width, height, CByteImage::eRGB24);
262 resizedImages =
new CByteImage*[getNumberImages()];
264 for (
int i = 0 ; i < getNumberImages() ; i++)
271 void ImageSequenceProvider::loadNextImage(
const Ice::Current&
c)
273 std::unique_lock lock(captureMutex);
275 loadNewImageAtNextCapture =
true;