31 #include <Calibration/StereoCalibration.h>
33 #include <SimoxUtility/algorithm/string/string_tools.h>
40 std::string
value = getProperty<std::string>(
"serialNumbers").getValue();
43 visionx::ImageDimension dimensions = getProperty<visionx::ImageDimension>(
"dimensions").getValue();
45 unsigned int numCameras;
46 if (busManager.GetNumOfCameras(&numCameras) != FlyCapture2::PGRERROR_OK && !numCameras)
48 ARMARX_FATAL <<
"no cameras found or unable to query bus";
52 ARMARX_INFO <<
"found " << numCameras <<
" cameras";
54 for (std::string& serialNumber : serialNumbers)
56 FlyCapture2::PGRGuid pGuid;
58 if (busManager.GetCameraFromSerialNumber(std::stoi(serialNumber), &pGuid) != FlyCapture2::PGRERROR_OK)
60 ARMARX_FATAL <<
"invalid serial number or camera not found: " << serialNumber;
67 if (
c->Connect(&pGuid) != FlyCapture2::PGRERROR_OK)
72 FlyCapture2::CameraInfo cameraInfo;
73 if (
c->GetCameraInfo(&cameraInfo) != FlyCapture2::PGRERROR_OK)
79 ARMARX_INFO <<
" camera model: " << cameraInfo.modelName <<
" serial number: `" << cameraInfo.serialNumber;
85 colorImages.push_back(
new FlyCapture2::Image(dimensions.height, dimensions.width, FlyCapture2::PIXEL_FORMAT_RGB, FlyCapture2::BayerTileFormat::RGGB));
89 cameraImages =
new CByteImage*[cameras.size()];
90 for (
size_t i = 0 ; i < cameras.size(); i++)
92 cameraImages[i] =
new CByteImage(dimensions.width, dimensions.height, CByteImage::eRGB24);
95 rectifyImages =
false;
97 undistortion =
new CUndistortion();
98 undistortImages = getProperty<bool>(
"UndistortImages").getValue();
99 undistortion->Init(calibrationFileName.c_str());
101 frameRate = getProperty<float>(
"FrameRate").getValue();
103 setNumberImages(cameras.size());
104 setImageFormat(dimensions, visionx::eRgb, visionx::eBayerPatternRg);
105 setImageSyncMode(visionx::eCaptureSynchronization);
114 if (
c->IsConnected())
122 for (FlyCapture2::Image* i : colorImages)
128 for (
size_t i = 0; i < cameras.size(); i++)
130 delete cameraImages[i];
133 delete [] cameraImages;
142 FlyCapture2::Property p;
146 p.type = FlyCapture2::AUTO_EXPOSURE;
147 p.absValue = getProperty<float>(
"Exposure").getValue();
148 p.autoManualMode = getProperty<float>(
"Exposure").getValue() >= 0;
149 if (
c->SetProperty(&p) != FlyCapture2::PGRERROR_OK)
154 p.type = FlyCapture2::SHUTTER;
155 p.absValue = getProperty<float>(
"Shutter").getValue();
156 p.autoManualMode = getProperty<float>(
"Shutter").getValue() >= 0;
157 if (
c->SetProperty(&p) != FlyCapture2::PGRERROR_OK)
162 p.type = FlyCapture2::GAIN;
163 p.absValue = getProperty<float>(
"Gain").getValue();
164 p.autoManualMode = getProperty<float>(
"Gain").getValue() >= 0;
165 if (
c->SetProperty(&p) != FlyCapture2::PGRERROR_OK)
171 FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_7_5;
173 if (framesPerSecond >= 60.0)
175 frameRate = FlyCapture2::FRAMERATE_60;
177 else if (framesPerSecond >= 30.0)
179 frameRate = FlyCapture2::FRAMERATE_30;
181 else if (framesPerSecond >= 15.0)
183 frameRate = FlyCapture2::FRAMERATE_15;
185 else if (framesPerSecond >= 7.5)
187 frameRate = FlyCapture2::FRAMERATE_7_5;
194 FlyCapture2::VideoMode mode = FlyCapture2::VideoMode::VIDEOMODE_640x480Y8;
197 if (getProperty<visionx::ImageDimension>(
"dimensions").getValue() == visionx::ImageDimension(640, 480))
199 mode = FlyCapture2::VideoMode::VIDEOMODE_640x480Y8;
201 else if (getProperty<visionx::ImageDimension>(
"dimensions").getValue() == visionx::ImageDimension(1600, 1200))
203 mode = FlyCapture2::VideoMode::VIDEOMODE_1600x1200Y8;
210 FlyCapture2::Error error =
c->SetVideoModeAndFrameRate(mode, frameRate);
212 if (error != FlyCapture2::PGRERROR_OK)
217 if (
c->StartCapture() != FlyCapture2::PGRERROR_OK)
235 const int imageSize = imageFormat.dimension.width * imageFormat.dimension.height * imageFormat.bytesPerPixel;
237 FlyCapture2::Image imageBuffer;
238 for (
size_t i = 0; i < cameras.size(); i++)
241 if (cameras[i]->RetrieveBuffer(&imageBuffer) != FlyCapture2::PGRERROR_OK)
248 if (imageBuffer.Convert(FlyCapture2::PIXEL_FORMAT_RGB, colorImages[i]) != FlyCapture2::PGRERROR_OK)
257 for (
size_t i = 0; i < cameras.size(); i++)
259 memcpy(cameraImages[i]->pixels, colorImages[i]->GetData(), imageSize);
271 for (
size_t i = 0; i < cameras.size(); i++)
273 memcpy(ppImageBuffers[i], cameraImages[i]->pixels, imageSize);
291 calibrationFileName = getProperty<std::string>(
"CalibrationFile") .getValue();
297 CStereoCalibration ivtStereoCalibration;
298 if (!ivtStereoCalibration.LoadCameraParameters(calibrationFileName.c_str(),
true))
303 rectifyImages = getProperty<bool>(
"RectifyImages").getValue();
304 rectification =
new CRectification(
true, undistortImages);
305 rectification->Init(calibrationFileName.c_str());