29 #include <rc_genicam_api/system.h>
30 #include <rc_genicam_api/interface.h>
31 #include <rc_genicam_api/buffer.h>
32 #include <rc_genicam_api/image.h>
33 #include <rc_genicam_api/config.h>
35 #include <rc_genicam_api/pixel_formats.h>
41 #include <Calibration/Calibration.h>
42 #include <Calibration/StereoCalibration.h>
52 defineOptionalProperty<std::string>(
"DeviceId",
"00_14_2d_2c_6e_ed",
"");
53 defineOptionalProperty<float>(
"ScaleFactor", 1.0,
"Image down scale factor");
54 defineOptionalProperty<float>(
"FrameRate", 25.0f,
"Frames per second")
55 .setMatchRegex(
"\\d+(.\\d*)?")
58 defineOptionalProperty<bool>(
"AutoExposure",
false,
"Enables auto exposure");
59 defineOptionalProperty<float>(
"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.").setMin(0.125).setMax(8.0);
66 defineOptionalProperty<float>(
"WhiteBalanceRatioBlue", 2.4f,
"Blue to green balance ratio.").setMin(0.125).setMax(8.0);
68 defineOptionalProperty<std::string>(
"ReferenceFrameName",
"Roboception_LeftCamera",
"Optional reference frame name.");
70 defineOptionalProperty<std::string>(
"RobotHealthTopicName",
"RobotHealthTopic",
"Name of the RobotHealth topic");
79 defs->optional(enableDepth,
"EnableDepth",
80 "Enables depth image, i.e. provide RGB (left) + Depth.\n"
81 "Note that the depth image is scaled up by 2 (nearest neighbour) to match the resolution of the color image.");
88 intensityBuffer(50), disparityBuffer(25)
94 void RCImageProvider::updateCameraSettings()
98 bool autoExposure = getProperty<bool>(
"AutoExposure");
99 float exposureTimeMs = getProperty<float>(
"ExposureTimeMs");
100 float gainDb = getProperty<float>(
"GainDb");
102 bool enableColor = getProperty<bool>(
"EnableColor").getValue();
104 std::shared_ptr<GenApi::CNodeMapRef>
nodemap =
dev->getRemoteNodeMap();
111 if (rcg::setEnum(
nodemap,
"PixelFormat",
"YCbCr411_8",
false))
124 if (getProperty<bool>(
"EnableAutoWhiteBalance").
getValue())
126 if (rcg::setEnum(
nodemap,
"BalanceWhiteAuto",
"Continuous"))
137 if (rcg::setEnum(
nodemap,
"BalanceWhiteAuto",
"Off"))
141 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Red");
142 if (!rcg::setFloat(
nodemap,
"BalanceRatio", getProperty<float>(
"WhiteBalanceRatioRed").
getValue()))
144 ARMARX_WARNING <<
"unable to set white balance ratio for red-green";
147 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Blue");
148 if (!rcg::setFloat(
nodemap,
"BalanceRatio", getProperty<float>(
"WhiteBalanceRatioBlue").
getValue()))
150 ARMARX_WARNING <<
"unable to set white balance ratio for green-blue";
160 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Red");
161 double wbRatioRed = rcg::getFloat(
nodemap,
"BalanceRatio");
163 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Blue");
164 double wbRatioBlue = rcg::getFloat(
nodemap,
"BalanceRatio");
166 ARMARX_INFO <<
"white balance ratio is red: " << wbRatioRed <<
" blue: " << wbRatioBlue;
170 if (rcg::setEnum(
nodemap,
"PixelFormat",
"Mono8",
false))
187 catch (std::invalid_argument& e)
197 ARMARX_INFO <<
"Setting auto exposure from " << oldAutoExposure <<
" to " << autoExposure;
200 ARMARX_WARNING <<
"Could not set auto exposure to: " << autoExposure;
203 ARMARX_INFO <<
"Setting exposure time from " << oldExposureTime <<
" to " << exposureTimeMs;
206 ARMARX_WARNING <<
"Could not set exposure time to: " << exposureTimeMs;
210 ARMARX_INFO <<
"Setting gain from " << oldGain <<
" to " << gainDb;
223 if (!
initDevice(getProperty<std::string>(
"DeviceId")))
249 updateCameraSettings();
252 getProperty<float>(
"ScaleFactor"),
253 "/tmp/armar6_rc_color_calibration.txt"
256 frameRate = getProperty<float>(
"FrameRate");
260 scan3dCoordinateScale = rcg::getFloat(
nodemap,
"Scan3dCoordinateScale",
nullptr,
nullptr,
true);
280 (void) framesPerSecond;
293 IceUtil::Time timeoutTime = IceUtil::Time::now(IceUtil::Time::Monotonic) + IceUtil::Time::secondsDouble(2);
294 while (IceUtil::Time::now(IceUtil::Time::Monotonic) < timeoutTime)
296 const rcg::Buffer* buffer =
stream->grab((timeoutTime - IceUtil::Time::now(IceUtil::Time::Monotonic)).toMilliSeconds());
304 catch (std::exception
const& ex)
312 catch (std::exception
const& ex)
319 getProperty<float>(
"ScaleFactor"),
320 "/tmp/armar6_rc_color_calibration.txt"
329 if (buffer->getIsIncomplete())
333 if (buffer->getNumberOfParts() > 1)
340 if (!buffer->getImagePresent(
part))
346 size_t px = buffer->getXPadding(
part);
347 uint64_t format = buffer->getPixelFormat(
part);
349 int width = imageFormat.dimension.width;
350 int height = imageFormat.dimension.height;
351 if (scaleFactor > 1.0f)
353 width *= scaleFactor;
354 height *= scaleFactor;
357 const int imageSize = imageFormat.dimension.width * imageFormat.dimension.height * imageFormat.bytesPerPixel;
364 const uint8_t* inputPixels =
static_cast<const uint8_t*
>(buffer->getBase(0));
369 inputPixels,
size_t(width),
size_t(height), format, px);
376 case PfncFormat::Mono8:
377 case PfncFormat::Confidence8:
379 case PfncFormat::YCbCr411_8:
380 intensityBuffer.add(buffer,
part);
383 disparityBuffer.add(buffer,
part);
386 ARMARX_INFO <<
"Unexpected pixel format: " << int(format);
390 uint64_t timestamp = buffer->getTimestampNS();
392 std::shared_ptr<const rcg::Image> intensity = intensityBuffer.find(timestamp);
393 std::shared_ptr<const rcg::Image> disparity = disparityBuffer.find(timestamp);
395 if (!intensity || !disparity)
401 ARMARX_DEBUG <<
"Received all synchronized images at timestamp " << buffer->getTimestamp() <<
".";
407 if (intensity->getWidth() / disparity->getWidth() == 2
408 && intensity->getHeight() / disparity->getHeight() == 2)
411 static bool reported =
false;
414 ARMARX_INFO <<
"Scaling up depth image by a factor of " << upscale <<
".";
430 if (scaleFactor > 1.0f)
437 memcpy(ppImageBuffers[i],
smallImages[i]->pixels, imageSize);
445 memcpy(ppImageBuffers[i],
cameraImages[i]->pixels, imageSize);