27 #include <SimoxUtility/algorithm/string/string_tools.h>
33 #include <Calibration/StereoCalibration.h>
40 std::string
value = getProperty<std::string>(
"serialNumbers").getValue();
43 visionx::ImageDimension dimensions =
44 getProperty<visionx::ImageDimension>(
"dimensions").getValue();
46 unsigned int numCameras;
47 if (busManager.GetNumOfCameras(&numCameras) != FlyCapture2::PGRERROR_OK && !numCameras)
49 ARMARX_FATAL <<
"no cameras found or unable to query bus";
53 ARMARX_INFO <<
"found " << numCameras <<
" cameras";
55 for (std::string& serialNumber : serialNumbers)
57 FlyCapture2::PGRGuid pGuid;
59 if (busManager.GetCameraFromSerialNumber(std::stoi(serialNumber), &pGuid) !=
60 FlyCapture2::PGRERROR_OK)
62 ARMARX_FATAL <<
"invalid serial number or camera not found: " << serialNumber;
68 if (
c->Connect(&pGuid) != FlyCapture2::PGRERROR_OK)
73 FlyCapture2::CameraInfo cameraInfo;
74 if (
c->GetCameraInfo(&cameraInfo) != FlyCapture2::PGRERROR_OK)
80 ARMARX_INFO <<
" camera model: " << cameraInfo.modelName <<
" serial number: `"
81 << cameraInfo.serialNumber;
87 colorImages.push_back(
new FlyCapture2::Image(dimensions.height,
89 FlyCapture2::PIXEL_FORMAT_RGB,
90 FlyCapture2::BayerTileFormat::RGGB));
94 cameraImages =
new CByteImage*[cameras.size()];
95 for (
size_t i = 0; i < cameras.size(); i++)
97 cameraImages[i] =
new CByteImage(dimensions.width, dimensions.height, CByteImage::eRGB24);
100 rectifyImages =
false;
102 undistortion =
new CUndistortion();
103 undistortImages = getProperty<bool>(
"UndistortImages").getValue();
104 undistortion->Init(calibrationFileName.c_str());
106 frameRate = getProperty<float>(
"FrameRate").getValue();
108 setNumberImages(cameras.size());
109 setImageFormat(dimensions, visionx::eRgb, visionx::eBayerPatternRg);
110 setImageSyncMode(visionx::eCaptureSynchronization);
118 if (
c->IsConnected())
126 for (FlyCapture2::Image* i : colorImages)
132 for (
size_t i = 0; i < cameras.size(); i++)
134 delete cameraImages[i];
137 delete[] cameraImages;
147 FlyCapture2::Property p;
151 p.type = FlyCapture2::AUTO_EXPOSURE;
152 p.absValue = getProperty<float>(
"Exposure").getValue();
153 p.autoManualMode = getProperty<float>(
"Exposure").getValue() >= 0;
154 if (
c->SetProperty(&p) != FlyCapture2::PGRERROR_OK)
159 p.type = FlyCapture2::SHUTTER;
160 p.absValue = getProperty<float>(
"Shutter").getValue();
161 p.autoManualMode = getProperty<float>(
"Shutter").getValue() >= 0;
162 if (
c->SetProperty(&p) != FlyCapture2::PGRERROR_OK)
167 p.type = FlyCapture2::GAIN;
168 p.absValue = getProperty<float>(
"Gain").getValue();
169 p.autoManualMode = getProperty<float>(
"Gain").getValue() >= 0;
170 if (
c->SetProperty(&p) != FlyCapture2::PGRERROR_OK)
176 FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_7_5;
178 if (framesPerSecond >= 60.0)
180 frameRate = FlyCapture2::FRAMERATE_60;
182 else if (framesPerSecond >= 30.0)
184 frameRate = FlyCapture2::FRAMERATE_30;
186 else if (framesPerSecond >= 15.0)
188 frameRate = FlyCapture2::FRAMERATE_15;
190 else if (framesPerSecond >= 7.5)
192 frameRate = FlyCapture2::FRAMERATE_7_5;
199 FlyCapture2::VideoMode mode = FlyCapture2::VideoMode::VIDEOMODE_640x480Y8;
202 if (getProperty<visionx::ImageDimension>(
"dimensions").getValue() ==
203 visionx::ImageDimension(640, 480))
205 mode = FlyCapture2::VideoMode::VIDEOMODE_640x480Y8;
207 else if (getProperty<visionx::ImageDimension>(
"dimensions").getValue() ==
208 visionx::ImageDimension(1600, 1200))
210 mode = FlyCapture2::VideoMode::VIDEOMODE_1600x1200Y8;
217 FlyCapture2::Error error =
c->SetVideoModeAndFrameRate(mode, frameRate);
219 if (error != FlyCapture2::PGRERROR_OK)
224 if (
c->StartCapture() != FlyCapture2::PGRERROR_OK)
244 const int imageSize =
245 imageFormat.dimension.width * imageFormat.dimension.height * imageFormat.bytesPerPixel;
247 FlyCapture2::Image imageBuffer;
248 for (
size_t i = 0; i < cameras.size(); i++)
251 if (cameras[i]->RetrieveBuffer(&imageBuffer) != FlyCapture2::PGRERROR_OK)
258 if (imageBuffer.Convert(FlyCapture2::PIXEL_FORMAT_RGB, colorImages[i]) !=
259 FlyCapture2::PGRERROR_OK)
268 for (
size_t i = 0; i < cameras.size(); i++)
270 memcpy(cameraImages[i]->pixels, colorImages[i]->GetData(), imageSize);
282 for (
size_t i = 0; i < cameras.size(); i++)
284 memcpy(ppImageBuffers[i], cameraImages[i]->pixels, imageSize);
303 calibrationFileName = getProperty<std::string>(
"CalibrationFile").getValue();
309 CStereoCalibration ivtStereoCalibration;
310 if (!ivtStereoCalibration.LoadCameraParameters(calibrationFileName.c_str(),
true))
315 rectifyImages = getProperty<bool>(
"RectifyImages").getValue();
316 rectification =
new CRectification(
true, undistortImages);
317 rectification->Init(calibrationFileName.c_str());