29#include <Calibration/Calibration.h>
30#include <Image/ImageProcessor.h>
51 k4aToIvtImage(
const k4a::image& color_image, ::CByteImage& result)
53 auto cw =
static_cast<unsigned int>(color_image.get_width_pixels());
54 auto ch =
static_cast<unsigned int>(color_image.get_height_pixels());
57 auto color_buffer =
reinterpret_cast<const unsigned char*
>(color_image.get_buffer());
58 auto rgb_buffer_ivt = result.pixels;
62 for (
unsigned int y = 0; y < ch; ++y)
64 for (
unsigned int x = 0;
x < cw; ++
x)
66 rgb_buffer_ivt[index_ivt] =
67 float(color_buffer[index_k4a] + color_buffer[index_k4a + 1]) / 2.f;
96 const uint32_t DEVICE_COUNT = k4a::device::get_installed_count();
97 if (DEVICE_COUNT == 0)
100 throw armarx::LocalException(
"No Azure Kinect devices detected!");
103 device = k4a::device::open(K4A_DEVICE_DEFAULT);
104 k4aCalibration = device.get_calibration(config.depth_mode, config.color_resolution);
106 transformation = k4a::transformation(k4aCalibration);
108 device.start_cameras(&config);
126 const std::chrono::milliseconds TIMEOUT{1000};
131 status = device.get_capture(&
capture, TIMEOUT);
133 catch (
const std::exception&)
135 ARMARX_WARNING <<
"Failed to get capture from device. Restarting camera.";
137 device.stop_cameras();
138 device.start_cameras(&config);
139 ARMARX_INFO <<
"Restarting took " << sw.stop() <<
".";
147 const k4a::image irImage =
capture.get_ir_image();
148 CByteImage buffer(depthDim.first, depthDim.second, CByteImage::eGrayScale);
149 k4aToIvtImage(irImage, buffer);
151 std::memcpy(pp_image_buffers[0], buffer.pixels, 1024 * 1024);
160 return "AzureKinectIRImageProvider";
166 config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
170 config.camera_fps = K4A_FRAMES_PER_SECOND_5;
172 else if (fps == 15.0f)
174 config.camera_fps = K4A_FRAMES_PER_SECOND_15;
176 else if (fps == 30.0f)
178 config.camera_fps = K4A_FRAMES_PER_SECOND_30;
182 throw armarx::LocalException(
"Invalid framerate: ")
183 << fps <<
" - Only framerates 5, 15 and 30 are "
184 <<
"supported by Azure Kinect.";
187 config.depth_mode = K4A_DEPTH_MODE_PASSIVE_IR;
188 config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
189 config.color_resolution = K4A_COLOR_RESOLUTION_1080P;
193 config.synchronized_images_only =
true;
198 ARMARX_INFO <<
"Depth image size: " << depthDim.first <<
"x" << depthDim.second;
199 ARMARX_INFO <<
"Color image size: " << color_dim.first <<
"x" << color_dim.second;
201 setImageFormat(visionx::ImageDimension(depthDim.first, depthDim.second),
203 visionx::eBayerPatternGr);
220 return std::string();
232 using namespace Eigen;
236 const auto convert_calibration =
237 [](
const k4a_calibration_camera_t& k4a_calib,
float scale = 1.)
239 MonocularCalibration calibration;
241 const k4a_calibration_intrinsic_parameters_t& params = k4a_calib.intrinsics.parameters;
242 calibration.cameraParam.principalPoint = {params.param.cx * scale,
243 params.param.cy * scale};
244 calibration.cameraParam.focalLength = {params.param.fx * scale,
245 params.param.fy * scale};
258 calibration.cameraParam.distortion = {
264 calibration.cameraParam.width = k4a_calib.resolution_width;
265 calibration.cameraParam.height = k4a_calib.resolution_height;
266 const Matrix3fRowMajor ROTATION =
267 Map<const Matrix3fRowMajor>{k4a_calib.extrinsics.rotation};
268 calibration.cameraParam.rotation = convertEigenMatToVisionX(ROTATION);
269 calibration.cameraParam.translation = {k4a_calib.extrinsics.translation,
270 k4a_calib.extrinsics.translation + 3};
275 StereoCalibration calibration;
277 calibration.calibrationLeft = calibration.calibrationRight =
278 convert_calibration(k4aCalibration.color_camera_calibration);
280 calibration.rectificationHomographyLeft = calibration.rectificationHomographyRight =
281 convertEigenMatToVisionX(Matrix3f::Identity());
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)
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.
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.
virtual std::string getDefaultName() const override
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.