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>
54 .setMatchRegex(
"\\d+(.\\d*)?")
59 "ExposureTimeMs", 12.0f,
"Exposure time in ms if auto exposure is disabled");
73 "ReferenceFrameName",
"Roboception_LeftCamera",
"Optional reference frame name.");
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.");
101RCImageProvider::updateCameraSettings()
111 std::shared_ptr<GenApi::CNodeMapRef>
nodemap =
dev->getRemoteNodeMap();
121 if (rcg::setEnum(
nodemap,
"PixelFormat",
"YCbCr411_8",
false))
136 if (rcg::setEnum(
nodemap,
"BalanceWhiteAuto",
"Continuous"))
147 if (rcg::setEnum(
nodemap,
"BalanceWhiteAuto",
"Off"))
151 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Red");
156 ARMARX_WARNING <<
"unable to set white balance ratio for red-green";
159 rcg::setEnum(
nodemap,
"BalanceRatioSelector",
"Blue");
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))
198 rcg::setEnum(
nodemap, GC_DEPTH_QUALITY, GC_DEPTH_QUALITY_HIGH,
true);
200 catch (std::invalid_argument& e)
204 <<
"' is currently not available for this device. "
206 rcg::setEnum(
nodemap, GC_DEPTH_QUALITY, GC_DEPTH_QUALITY_HIGH,
true);
210 std::string oldAutoExposure = rcg::getEnum(
nodemap, GC_EXPOSURE_AUTO,
false);
211 ARMARX_INFO <<
"Setting auto exposure from " << oldAutoExposure <<
" to " << autoExposure;
212 if (!rcg::setEnum(
nodemap, GC_EXPOSURE_AUTO, autoExposure ?
"Continuous" :
"Off",
false))
214 ARMARX_WARNING <<
"Could not set auto exposure to: " << autoExposure;
216 double oldExposureTime = rcg::getFloat(
nodemap, GC_EXPOSURE_TIME) / 1000.0;
217 ARMARX_INFO <<
"Setting exposure time from " << oldExposureTime <<
" to " << exposureTimeMs;
218 if (!rcg::setFloat(
nodemap, GC_EXPOSURE_TIME, exposureTimeMs * 1000.0,
false))
220 ARMARX_WARNING <<
"Could not set exposure time to: " << exposureTimeMs;
223 double oldGain = rcg::getFloat(
nodemap, GC_GAIN);
224 ARMARX_INFO <<
"Setting gain from " << oldGain <<
" to " << gainDb;
225 if (!rcg::setFloat(
nodemap, GC_GAIN, gainDb,
false))
264 updateCameraSettings();
267 "/tmp/armar6_rc_color_calibration.txt");
273 scan3dCoordinateScale = rcg::getFloat(
nodemap,
"Scan3dCoordinateScale",
nullptr,
nullptr,
true);
296 (void)framesPerSecond;
311 IceUtil::Time timeoutTime =
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);
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
RCImageProviderPropertyDefinitions(std::string prefix)
void onStartCapture(float frameRate) override
This is called when the image provider capturing has been started.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onStartCapturingImageProvider() override
This is called when the Component::onConnectComponent() setup is called.
void onStopCapture() override
This is called when the image provider capturing has been stopped.
void onExitCapturingImageProvider() override
This is called when the Component::onExitComponent() setup is called.
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
float frameRate
Required frame rate.
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
armarx::IceSharedMemoryProvider< unsignedchar >::pointer_type sharedMemoryProvider
shared memory provider
void updateTimestamp(Ice::Long timestamp, bool threadSafe=true)
Updates the timestamp of the currently captured image.
ImageFormatInfo getImageFormat(const Ice::Current &c=Ice::emptyCurrent) override
Returns the entire image format info struct via Ice.
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
void setNumberImages(int numberImages)
Sets the number of images on each capture.
CByteImage ** cameraImages
void enableDisparity(bool enabled)
void enableError(bool enabled)
void enableIntensityCombined(bool enabled)
std::shared_ptr< GenApi::CNodeMapRef > nodemap
bool initDevice(const std::string &dname)
void enableConfidence(bool enabled)
CByteImage ** smallImages
void enableIntensity(bool enabled)
void setupStreamAndCalibration(float scalefactor, const std::string &calibSavePath)
visionx::ImageDimension dimensions
static void fillCameraImageDepth(unsigned char *outputPixels, double f, double t, double scale, const rcg::Image &disparity, size_t upscale=1)
static void fillCameraImageRGB(unsigned char *outputPixels, size_t nImage, const uint8_t *inputPixels, size_t width, size_t height, uint64_t pixelFormat, size_t xpadding)
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const char *const GC_DEPTH_QUALITY_HIGH
const char *const GC_COMPONENT_SELECTOR
const char *const GC_DEPTH_QUALITY_FULL