36 #include <Calibration/Calibration.h>
37 #include <Calibration/StereoCalibration.h>
38 #include <rc_genicam_api/buffer.h>
39 #include <rc_genicam_api/config.h>
40 #include <rc_genicam_api/image.h>
41 #include <rc_genicam_api/interface.h>
42 #include <rc_genicam_api/pixel_formats.h>
43 #include <rc_genicam_api/system.h>
51 defineOptionalProperty<std::string>(
"DeviceId",
"00_14_2d_2c_6e_ed",
"");
52 defineOptionalProperty<float>(
"ScaleFactor", 1.0,
"Image down scale factor");
53 defineOptionalProperty<float>(
"FrameRate", 25.0f,
"Frames per second")
54 .setMatchRegex(
"\\d+(.\\d*)?")
57 defineOptionalProperty<bool>(
"AutoExposure",
false,
"Enables auto exposure");
58 defineOptionalProperty<float>(
59 "ExposureTimeMs", 12.0f,
"Exposure time in ms if auto exposure is disabled");
60 defineOptionalProperty<float>(
"GainDb", 0.0f,
"Gain in db");
62 defineOptionalProperty<bool>(
"EnableColor",
true,
"Enables colored images");
64 defineOptionalProperty<bool>(
"EnableAutoWhiteBalance",
false,
"Enable auto white balance");
65 defineOptionalProperty<float>(
"WhiteBalanceRatioRed", 1.2f,
"Red to green balance ratio.")
68 defineOptionalProperty<float>(
"WhiteBalanceRatioBlue", 2.4f,
"Blue to green balance ratio.")
72 defineOptionalProperty<std::string>(
73 "ReferenceFrameName",
"Roboception_LeftCamera",
"Optional reference frame name.");
75 defineOptionalProperty<std::string>(
76 "RobotHealthTopicName",
"RobotHealthTopic",
"Name of the RobotHealth topic");
87 defs->optional(enableDepth,
89 "Enables depth image, i.e. provide RGB (left) + Depth.\n"
90 "Note that the depth image is scaled up by 2 (nearest neighbour) to match the "
91 "resolution of the color image.");
101 RCImageProvider::updateCameraSettings()
105 bool autoExposure = getProperty<bool>(
"AutoExposure");
106 float exposureTimeMs = getProperty<float>(
"ExposureTimeMs");
107 float gainDb = getProperty<float>(
"GainDb");
109 bool enableColor = getProperty<bool>(
"EnableColor").getValue();
111 std::shared_ptr<GenApi::CNodeMapRef>
nodemap =
dev->getRemoteNodeMap();
121 if (rcg::setEnum(
nodemap,
"PixelFormat",
"YCbCr411_8",
false))
134 if (getProperty<bool>(
"EnableAutoWhiteBalance").
getValue())
136 if (rcg::setEnum(
nodemap,
"BalanceWhiteAuto",
"Continuous"))
147 if (rcg::setEnum(
nodemap,
"BalanceWhiteAuto",
"Off"))
151 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Red");
154 getProperty<float>(
"WhiteBalanceRatioRed").
getValue()))
156 ARMARX_WARNING <<
"unable to set white balance ratio for red-green";
159 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Blue");
162 getProperty<float>(
"WhiteBalanceRatioBlue").
getValue()))
164 ARMARX_WARNING <<
"unable to set white balance ratio for green-blue";
173 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Red");
174 double wbRatioRed = rcg::getFloat(
nodemap,
"BalanceRatio");
176 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Blue");
177 double wbRatioBlue = rcg::getFloat(
nodemap,
"BalanceRatio");
179 ARMARX_INFO <<
"white balance ratio is red: " << wbRatioRed <<
" blue: " << wbRatioBlue;
183 if (rcg::setEnum(
nodemap,
"PixelFormat",
"Mono8",
false))
200 catch (std::invalid_argument& e)
204 <<
"' is currently not available for this device. "
211 ARMARX_INFO <<
"Setting auto exposure from " << oldAutoExposure <<
" to " << autoExposure;
214 ARMARX_WARNING <<
"Could not set auto exposure to: " << autoExposure;
217 ARMARX_INFO <<
"Setting exposure time from " << oldExposureTime <<
" to " << exposureTimeMs;
220 ARMARX_WARNING <<
"Could not set exposure time to: " << exposureTimeMs;
224 ARMARX_INFO <<
"Setting gain from " << oldGain <<
" to " << gainDb;
238 if (!
initDevice(getProperty<std::string>(
"DeviceId")))
264 updateCameraSettings();
267 "/tmp/armar6_rc_color_calibration.txt");
269 frameRate = getProperty<float>(
"FrameRate");
273 scan3dCoordinateScale = rcg::getFloat(
nodemap,
"Scan3dCoordinateScale",
nullptr,
nullptr,
true);
296 (void)framesPerSecond;
312 IceUtil::Time::now(IceUtil::Time::Monotonic) + IceUtil::Time::secondsDouble(2);
313 while (IceUtil::Time::now(IceUtil::Time::Monotonic) < timeoutTime)
315 const rcg::Buffer* buffer =
stream->grab(
316 (timeoutTime - IceUtil::Time::now(IceUtil::Time::Monotonic)).toMilliSeconds());
320 <<
"buffer is NULL - Unable to get image - restarting streaming";
325 catch (std::exception
const& ex)
333 catch (std::exception
const& ex)
340 "/tmp/armar6_rc_color_calibration.txt");
348 if (buffer->getIsIncomplete())
352 if (buffer->getNumberOfParts() > 1)
359 if (!buffer->getImagePresent(
part))
365 size_t px = buffer->getXPadding(
part);
366 uint64_t format = buffer->getPixelFormat(
part);
368 int width = imageFormat.dimension.width;
369 int height = imageFormat.dimension.height;
370 if (scaleFactor > 1.0f)
372 width *= scaleFactor;
373 height *= scaleFactor;
376 const int imageSize =
377 imageFormat.dimension.width * imageFormat.dimension.height * imageFormat.bytesPerPixel;
384 const uint8_t* inputPixels =
static_cast<const uint8_t*
>(buffer->getBase(0));
401 case PfncFormat::Mono8:
402 case PfncFormat::Confidence8:
404 case PfncFormat::YCbCr411_8:
405 intensityBuffer.add(buffer,
part);
408 disparityBuffer.add(buffer,
part);
411 ARMARX_INFO <<
"Unexpected pixel format: " << int(format);
415 uint64_t timestamp = buffer->getTimestampNS();
417 std::shared_ptr<const rcg::Image> intensity = intensityBuffer.find(timestamp);
418 std::shared_ptr<const rcg::Image> disparity = disparityBuffer.find(timestamp);
420 if (!intensity || !disparity)
426 ARMARX_DEBUG <<
"Received all synchronized images at timestamp "
427 << buffer->getTimestamp() <<
".";
433 if (intensity->getWidth() / disparity->getWidth() == 2 &&
434 intensity->getHeight() / disparity->getHeight() == 2)
437 static bool reported =
false;
440 ARMARX_INFO <<
"Scaling up depth image by a factor of " << upscale <<
".";
451 scan3dCoordinateScale,
459 if (scaleFactor > 1.0f)
466 memcpy(ppImageBuffers[i],
smallImages[i]->pixels, imageSize);
474 memcpy(ppImageBuffers[i],
cameraImages[i]->pixels, imageSize);