25 #include <rc_genicam_api/system.h>
26 #include <rc_genicam_api/interface.h>
27 #include <rc_genicam_api/buffer.h>
28 #include <rc_genicam_api/image.h>
29 #include <rc_genicam_api/config.h>
30 #include <rc_genicam_api/pixel_formats.h>
39 #include <Calibration/Calibration.h>
40 #include <Calibration/StereoCalibration.h>
41 #include <Image/ImageProcessor.h>
59 if (!getenv(
"GENICAM_GENTL64_PATH"))
61 setenv(
"GENICAM_GENTL64_PATH",
"/usr/lib/rc_genicam_api/", 0);
63 dev = rcg::getDevice(dname.c_str());
67 const auto dname2 =
"devicemodul" + dname;
68 dev = rcg::getDevice(dname2.c_str());
74 dev->open(rcg::Device::EXCLUSIVE);
75 nodemap = dev->getRemoteNodeMap();
80 std::vector<std::shared_ptr<rcg::Device> > devices = rcg::getDevices();
81 ARMARX_INFO <<
"found " << devices.size() <<
" devices";
85 if (dname == d->getID())
87 ARMARX_ERROR <<
"Device: " << d->getID() <<
" !!!(THIS IS THE DEVICE YOU REQUESTED)!!!";
96 ARMARX_INFO <<
"Display name: " << d->getDisplayName();
97 ARMARX_INFO <<
"Access status:" << d->getAccessStatus();
98 ARMARX_INFO <<
"User name: " << d->getUserDefinedName();
99 ARMARX_INFO <<
"Serial number: " << d->getSerialNumber();
101 ARMARX_INFO <<
"TS Frequency: " << d->getTimestampFrequency();
104 ARMARX_ERROR <<
"Please specify the device id. Aborting";
143 if (!rcg::setBoolean(nodemap,
"GevIEEE1588",
true))
145 ARMARX_WARNING <<
"Could not activate Precision Time Protocol (PTP) client!";
148 dimensions.height =
Ice::Int(rcg::getInteger(nodemap,
"Height") / 2.0);
149 dimensions.width =
Ice::Int(rcg::getInteger(nodemap,
"Width"));
152 baseline = rcg::getFloat(nodemap,
"Baseline",
nullptr,
nullptr,
true);
153 focalLengthFactor = rcg::getFloat(nodemap,
"FocalLengthFactor",
nullptr,
nullptr,
false);
154 float focalLength =
float(focalLengthFactor * dimensions.width);
160 std::vector<rcg::StreamPtr> availableStreams = dev->getStreams();
167 if (!availableStreams.size())
174 this->stream = availableStreams[0];
179 cameraImages =
new CByteImage*[numImages];
180 for (
size_t i = 0 ; i < numImages; i++)
182 cameraImages[i] =
new CByteImage(dimensions.width, dimensions.height, CByteImage::eRGB24);
185 scaleFactor = scalefactor;
186 if (scaleFactor > 1.0)
188 dimensions.height /= scaleFactor;
189 dimensions.width /= scaleFactor;
190 focalLength /= scaleFactor;
193 smallImages =
new CByteImage*[numImages];
194 for (
size_t i = 0 ; i < numImages; i++)
196 smallImages[i] =
new CByteImage(dimensions.width, dimensions.height, CByteImage::eRGB24);
200 c.SetCameraParameters(focalLength, focalLength, dimensions.width / 2.0, dimensions.height / 2.0,
202 Math3d::unit_mat, Math3d::zero_vec, dimensions.width, dimensions.height);
204 CStereoCalibration ivtStereoCalibration;
205 ivtStereoCalibration.SetSingleCalibrations(
c,
c);
206 ivtStereoCalibration.rectificationHomographyRight = Math3d::unit_mat;
207 ivtStereoCalibration.rectificationHomographyLeft = Math3d::unit_mat;
209 Vec3d right_translation;
210 right_translation.x = baseline * -1000.0;
211 right_translation.y = 0.0;
212 right_translation.z = 0.0;
213 ivtStereoCalibration.SetExtrinsicParameters(Math3d::unit_mat, Math3d::zero_vec, Math3d::unit_mat, right_translation,
false);
215 ARMARX_INFO <<
"Saving calibration to: " << calibSavePath;
216 ivtStereoCalibration.SaveCameraParameters(calibSavePath.c_str());
222 ARMARX_INFO <<
"Start streaming Roboception Images";
225 stream->startStreaming();
230 ARMARX_INFO <<
"Stop streaming Roboception Images";
231 stream->stopStreaming();
239 stream->stopStreaming();
248 for (
size_t i = 0; i < numImages; i++)
250 delete cameraImages[i];
251 delete smallImages[i];
254 delete [] cameraImages;
255 delete [] smallImages;
260 GenApi::NodeList_t nodeList;
261 nodemap->_GetNodes(nodeList);
263 for (
const auto& node : nodeList)
265 ARMARX_INFO <<
"---- properties of node '" << node->GetName(
true) <<
'\'';
266 GENICAM_NAMESPACE::gcstring_vector properties;
267 node->GetPropertyNames(properties);
268 for (
const auto&
string : properties)
276 const uint8_t* inputPixels,
size_t width,
size_t height, uint64_t pixelFormat,
size_t xpadding)
278 const unsigned char* p = inputPixels;
282 case PfncFormat::Mono8:
283 case PfncFormat::Confidence8:
286 unsigned char const* row = p + (nImage * height) * (width + xpadding);
287 unsigned char* outRow = outputPixels;
288 for (
size_t j = 0; j < height; j++)
290 for (
size_t i = 0; i < width; i++)
292 const unsigned char c = row[i];
293 outRow[3 * i + 0] =
c;
294 outRow[3 * i + 1] =
c;
295 outRow[3 * i + 2] =
c;
300 row += width + xpadding;
304 case PfncFormat::YCbCr411_8:
307 size_t inStride = width * 6 / 4 + xpadding;
308 unsigned char const* row = p + (nImage * height) * inStride;
309 unsigned char* outRow = outputPixels;
311 for (
size_t j = 0; j < height; j++)
313 for (
size_t i = 0; i < width; i++)
315 rcg::convYCbCr411toRGB(rgb, row,
int(i));
316 outRow[i * 3 + 0] = rgb[0];
317 outRow[i * 3 + 1] = rgb[1];
318 outRow[i * 3 + 2] = rgb[2];
327 ARMARX_INFO <<
"Unexpected pixel format: " << int(pixelFormat);
335 fillCameraImageRGB(outputPixels, nImage, inputRgb.getPixels(), inputRgb.getWidth(), inputRgb.getHeight(),
336 inputRgb.getPixelFormat(), inputRgb.getXPadding());
341 unsigned char* outputPixels,
342 double f,
double t,
double scale,
const rcg::Image& disparity,
size_t upscale)
344 ARMARX_CHECK(upscale == 1 || upscale == 2) <<
"Upscaling by factors other than 1 or 2 is not implemented.";
349 size_t width = disparity.getWidth();
350 size_t height = disparity.getHeight();
351 bool bigendian = disparity.isBigEndian();
359 const uint8_t* dps = disparity.getPixels();
362 size_t dstep = disparity.getWidth() *
sizeof(uint16_t) + disparity.getXPadding();
367 disparity.getXPadding();
368 unsigned char* outRow = outputPixels;
370 for (
size_t j = 0; j < height; j++)
372 for (
size_t i = 0; i < width; i++)
379 d = scale * ((dps[j] << 8) | dps[j + 1]);
384 d = scale * ((dps[j + 1] << 8) | dps[j]);
387 unsigned char* pixel = &outRow[3 * i * upscale];
393 double z = f * t / d;
396 const double meterToMillimeter = 1000.0;
397 unsigned int depthMM =
static_cast<unsigned int>(std::round(z * meterToMillimeter));
411 unsigned char* nextPixel = pixel + 3;
412 std::memcpy(nextPixel, pixel, 3);
419 unsigned char* nextRow = outRow + width * 3 * upscale;
420 std::memcpy(nextRow, outRow, width * 3 * upscale);
425 outRow += width * 3 * upscale;