31#include <Calibration/Calibration.h>
32#include <Image/ImageProcessor.h>
53 k4aToIvtImage(
const k4a::image& color_image, ::CByteImage& result)
55 auto cw =
static_cast<unsigned int>(color_image.get_width_pixels());
56 auto ch =
static_cast<unsigned int>(color_image.get_height_pixels());
59 auto color_buffer =
reinterpret_cast<const unsigned char*
>(color_image.get_buffer());
60 auto rgb_buffer_ivt = result.pixels;
64 for (
unsigned int y = 0; y < ch; ++y)
66 for (
unsigned int x = 0;
x < cw; ++
x)
68 rgb_buffer_ivt[index_ivt] =
69 float(color_buffer[index_k4a] + color_buffer[index_k4a + 1]) / 2.f;
98 const uint32_t DEVICE_COUNT = k4a::device::get_installed_count();
99 if (DEVICE_COUNT == 0)
102 throw armarx::LocalException(
"No Azure Kinect devices detected!");
105 device = k4a::device::open(K4A_DEVICE_DEFAULT);
106 k4aCalibration = device.get_calibration(config.depth_mode, config.color_resolution);
108 transformation = k4a::transformation(k4aCalibration);
110 device.start_cameras(&config);
128 const std::chrono::milliseconds TIMEOUT{1000};
133 status = device.get_capture(&
capture, TIMEOUT);
135 catch (
const std::exception&)
137 ARMARX_WARNING <<
"Failed to get capture from device. Restarting camera.";
139 device.stop_cameras();
140 device.start_cameras(&config);
141 ARMARX_INFO <<
"Restarting took " << sw.stop() <<
".";
149 const k4a::image irImage =
capture.get_ir_image();
150 CByteImage buffer(depthDim.first, depthDim.second, CByteImage::eGrayScale);
151 k4aToIvtImage(irImage, buffer);
153 std::memcpy(pp_image_buffers[0], buffer.pixels, 1024 * 1024);
162 return "AzureKinectIRImageProvider";
174 config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
178 config.camera_fps = K4A_FRAMES_PER_SECOND_5;
180 else if (fps == 15.0f)
182 config.camera_fps = K4A_FRAMES_PER_SECOND_15;
184 else if (fps == 30.0f)
186 config.camera_fps = K4A_FRAMES_PER_SECOND_30;
190 throw armarx::LocalException(
"Invalid framerate: ")
191 << fps <<
" - Only framerates 5, 15 and 30 are "
192 <<
"supported by Azure Kinect.";
195 config.depth_mode = K4A_DEPTH_MODE_PASSIVE_IR;
196 config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
197 config.color_resolution = K4A_COLOR_RESOLUTION_1080P;
201 config.synchronized_images_only =
true;
206 ARMARX_INFO <<
"Depth image size: " << depthDim.first <<
"x" << depthDim.second;
207 ARMARX_INFO <<
"Color image size: " << color_dim.first <<
"x" << color_dim.second;
209 setImageFormat(visionx::ImageDimension(depthDim.first, depthDim.second),
211 visionx::eBayerPatternGr);
228 return std::string();
240 using namespace Eigen;
244 const auto convert_calibration =
245 [](
const k4a_calibration_camera_t& k4a_calib,
float scale = 1.)
247 MonocularCalibration calibration;
249 const k4a_calibration_intrinsic_parameters_t& params = k4a_calib.intrinsics.parameters;
250 calibration.cameraParam.principalPoint = {params.param.cx * scale,
251 params.param.cy * scale};
252 calibration.cameraParam.focalLength = {params.param.fx * scale,
253 params.param.fy * scale};
266 calibration.cameraParam.distortion = {
272 calibration.cameraParam.width = k4a_calib.resolution_width;
273 calibration.cameraParam.height = k4a_calib.resolution_height;
274 const Matrix3fRowMajor ROTATION =
275 Map<const Matrix3fRowMajor>{k4a_calib.extrinsics.rotation};
276 calibration.cameraParam.rotation = convertEigenMatToVisionX(ROTATION);
277 calibration.cameraParam.translation = {k4a_calib.extrinsics.translation,
278 k4a_calib.extrinsics.translation + 3};
283 StereoCalibration calibration;
285 calibration.calibrationLeft = calibration.calibrationRight =
286 convert_calibration(k4aCalibration.color_camera_calibration);
288 calibration.rectificationHomographyLeft = calibration.rectificationHomographyRight =
289 convertEigenMatToVisionX(Matrix3f::Identity());
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Eigen::Matrix< T, 3, 3 > Matrix
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void setMetaInfo(const std::string &id, const VariantBasePtr &value)
Allows to set meta information that can be queried live via Ice interface on the ArmarXManager.
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.
The Variant class is described here: Variants.
Measures the passed time between the construction or calling reset() and stop().
AzureKinectIRImageProviderPropertyDefinitions(std::string prefix)
Brief description of class AzureKinectIRImageProvider.
bool capture(void **pp_image_buffers) override
Main capturing function.
static std::pair< int, int > GetDepthDimensions(const k4a_depth_mode_t depth_mode)
void onStartCapture(float frames_per_second) override
This is called when the image provider capturing has been started.
static std::pair< int, int > GetColorDimensions(const k4a_color_resolution_t resolution)
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
static std::string VersionToString(const k4a_version_t &version)
bool getImagesAreUndistorted(const Ice::Current ¤t) override
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.
static std::string GetDefaultName()
std::string getReferenceFrame(const Ice::Current ¤t) override
StereoCalibration getStereoCalibration(const Ice::Current ¤t) override
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
std::string getDefaultName() const override
Retrieve default name of component.
float frameRate
Required frame rate.
CapturingPointCloudProviderPropertyDefinitions(std::string prefix)
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.
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.