Fix transform create when no rgb camera opened
(cherry picked from commit 93a36c648f
)
This commit is contained in:
Родитель
8b5bc34348
Коммит
6bc22f9f47
|
@ -13,6 +13,9 @@ k4a_result_t transformation_get_mode_specific_calibration(const k4a_calibration_
|
|||
const k4a_color_resolution_t color_resolution,
|
||||
k4a_calibration_t *calibration)
|
||||
{
|
||||
memset(&calibration->color_camera_calibration, 0, sizeof(k4a_calibration_camera_t));
|
||||
memset(&calibration->depth_camera_calibration, 0, sizeof(k4a_calibration_camera_t));
|
||||
|
||||
if (K4A_FAILED(
|
||||
K4A_RESULT_FROM_BOOL(color_resolution != K4A_COLOR_RESOLUTION_OFF || depth_mode != K4A_DEPTH_MODE_OFF)))
|
||||
{
|
||||
|
@ -334,7 +337,8 @@ typedef struct _k4a_transformation_context_t
|
|||
float *memory_depth_camera_xy_tables;
|
||||
k4a_transformation_xy_tables_t color_camera_xy_tables;
|
||||
float *memory_color_camera_xy_tables;
|
||||
bool gpu_optimization;
|
||||
bool enable_gpu_optimization;
|
||||
bool enable_depth_color_transform;
|
||||
k4a_transform_engine_context_t *transform_engine;
|
||||
} k4a_transformation_context_t;
|
||||
|
||||
|
@ -365,8 +369,12 @@ k4a_transformation_t transformation_create(const k4a_calibration_t *calibration,
|
|||
return 0;
|
||||
}
|
||||
|
||||
transformation_context->gpu_optimization = gpu_optimization;
|
||||
if (transformation_context->gpu_optimization)
|
||||
transformation_context->enable_gpu_optimization = gpu_optimization;
|
||||
transformation_context->enable_depth_color_transform = transformation_context->calibration.color_resolution !=
|
||||
K4A_COLOR_RESOLUTION_OFF &&
|
||||
transformation_context->calibration.depth_mode !=
|
||||
K4A_DEPTH_MODE_OFF;
|
||||
if (transformation_context->enable_gpu_optimization && transformation_context->enable_depth_color_transform)
|
||||
{
|
||||
// Set up transform engine expected calibration struct
|
||||
k4a_transform_engine_calibration_t transform_engine_calibration;
|
||||
|
@ -432,7 +440,13 @@ transformation_depth_image_to_color_camera(k4a_transformation_t transformation_h
|
|||
RETURN_VALUE_IF_HANDLE_INVALID(K4A_RESULT_FAILED, k4a_transformation_t, transformation_handle);
|
||||
k4a_transformation_context_t *transformation_context = k4a_transformation_t_get_context(transformation_handle);
|
||||
|
||||
if (transformation_context->gpu_optimization)
|
||||
if (!transformation_context->enable_depth_color_transform)
|
||||
{
|
||||
LOG_ERROR("Require both depth camera and color camera are opened to transform depth image to color camera.", 0);
|
||||
return K4A_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (transformation_context->enable_gpu_optimization)
|
||||
{
|
||||
size_t depth_image_size = (size_t)(depth_image_descriptor->stride_bytes *
|
||||
depth_image_descriptor->height_pixels);
|
||||
|
@ -493,7 +507,13 @@ transformation_color_image_to_depth_camera(k4a_transformation_t transformation_h
|
|||
RETURN_VALUE_IF_HANDLE_INVALID(K4A_RESULT_FAILED, k4a_transformation_t, transformation_handle);
|
||||
k4a_transformation_context_t *transformation_context = k4a_transformation_t_get_context(transformation_handle);
|
||||
|
||||
if (transformation_context->gpu_optimization)
|
||||
if (!transformation_context->enable_depth_color_transform)
|
||||
{
|
||||
LOG_ERROR("Require both depth camera and color camera are opened to transform color image to depth camera.", 0);
|
||||
return K4A_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (transformation_context->enable_gpu_optimization)
|
||||
{
|
||||
size_t depth_image_size = (size_t)(depth_image_descriptor->stride_bytes *
|
||||
depth_image_descriptor->height_pixels);
|
||||
|
|
|
@ -297,6 +297,108 @@ TEST_F(transformation_ut, transformation_2d_to_2d)
|
|||
ASSERT_EQ_FLT2(point2d, m_depth_point2d_reference);
|
||||
}
|
||||
|
||||
TEST_F(transformation_ut, transformation_create_depth_only)
|
||||
{
|
||||
k4a_depth_mode_t depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
|
||||
k4a_color_resolution_t color_resolution = K4A_COLOR_RESOLUTION_OFF;
|
||||
|
||||
k4a_calibration_t calibration;
|
||||
k4a_result_t result =
|
||||
k4a_calibration_get_from_raw(g_test_json, sizeof(g_test_json), depth_mode, color_resolution, &calibration);
|
||||
ASSERT_EQ(result, K4A_RESULT_SUCCEEDED);
|
||||
|
||||
k4a_transformation_t transformation = k4a_transformation_create(&calibration);
|
||||
ASSERT_NE(transformation, (k4a_transformation_t)NULL);
|
||||
|
||||
k4a_image_t depth_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16, 640, 576, 640 * 1 * (int)sizeof(uint16_t), &depth_image);
|
||||
|
||||
k4a_image_t color_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16, 1920, 1080, 1920 * 4 * (int)sizeof(uint8_t), &color_image);
|
||||
|
||||
k4a_image_t transformed_color_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_COLOR_BGRA32,
|
||||
k4a_image_get_width_pixels(depth_image),
|
||||
k4a_image_get_height_pixels(depth_image),
|
||||
k4a_image_get_width_pixels(depth_image) * 4 * (int)sizeof(uint8_t),
|
||||
&transformed_color_image);
|
||||
|
||||
k4a_image_t transformed_depth_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16,
|
||||
k4a_image_get_width_pixels(color_image),
|
||||
k4a_image_get_height_pixels(color_image),
|
||||
k4a_image_get_width_pixels(color_image) * 1 * (int)sizeof(uint16_t),
|
||||
&transformed_depth_image);
|
||||
|
||||
ASSERT_NE(k4a_transformation_color_image_to_depth_camera(transformation,
|
||||
depth_image,
|
||||
color_image,
|
||||
transformed_color_image),
|
||||
K4A_RESULT_SUCCEEDED);
|
||||
|
||||
ASSERT_NE(k4a_transformation_depth_image_to_color_camera(transformation, depth_image, transformed_depth_image),
|
||||
K4A_RESULT_SUCCEEDED);
|
||||
|
||||
k4a_image_t point_cloud_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_CUSTOM,
|
||||
k4a_image_get_width_pixels(depth_image),
|
||||
k4a_image_get_height_pixels(depth_image),
|
||||
k4a_image_get_width_pixels(depth_image) * 3 * (int)sizeof(int16_t),
|
||||
&point_cloud_image);
|
||||
|
||||
ASSERT_EQ(k4a_transformation_depth_image_to_point_cloud(transformation,
|
||||
depth_image,
|
||||
K4A_CALIBRATION_TYPE_DEPTH,
|
||||
point_cloud_image),
|
||||
K4A_RESULT_SUCCEEDED);
|
||||
}
|
||||
|
||||
TEST_F(transformation_ut, transformation_create_color_only)
|
||||
{
|
||||
k4a_depth_mode_t depth_mode = K4A_DEPTH_MODE_OFF;
|
||||
k4a_color_resolution_t color_resolution = K4A_COLOR_RESOLUTION_720P;
|
||||
|
||||
k4a_calibration_t calibration;
|
||||
k4a_result_t result =
|
||||
k4a_calibration_get_from_raw(g_test_json, sizeof(g_test_json), depth_mode, color_resolution, &calibration);
|
||||
ASSERT_EQ(result, K4A_RESULT_SUCCEEDED);
|
||||
|
||||
k4a_transformation_t transformation = k4a_transformation_create(&calibration);
|
||||
ASSERT_NE(transformation, (k4a_transformation_t)NULL);
|
||||
|
||||
k4a_image_t depth_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16, 640, 576, 640 * 1 * (int)sizeof(uint16_t), &depth_image);
|
||||
|
||||
k4a_image_t color_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16, 1920, 1080, 1920 * 4 * (int)sizeof(uint8_t), &color_image);
|
||||
|
||||
k4a_image_t transformed_color_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_COLOR_BGRA32,
|
||||
k4a_image_get_width_pixels(depth_image),
|
||||
k4a_image_get_height_pixels(depth_image),
|
||||
k4a_image_get_width_pixels(depth_image) * 4 * (int)sizeof(uint8_t),
|
||||
&transformed_color_image);
|
||||
|
||||
k4a_image_t transformed_depth_image = NULL;
|
||||
k4a_image_create(K4A_IMAGE_FORMAT_DEPTH16,
|
||||
k4a_image_get_width_pixels(color_image),
|
||||
k4a_image_get_height_pixels(color_image),
|
||||
k4a_image_get_width_pixels(color_image) * 1 * (int)sizeof(uint16_t),
|
||||
&transformed_depth_image);
|
||||
|
||||
ASSERT_NE(k4a_transformation_color_image_to_depth_camera(transformation,
|
||||
depth_image,
|
||||
color_image,
|
||||
transformed_color_image),
|
||||
K4A_RESULT_SUCCEEDED);
|
||||
|
||||
ASSERT_NE(k4a_transformation_depth_image_to_color_camera(transformation, depth_image, transformed_depth_image),
|
||||
K4A_RESULT_SUCCEEDED);
|
||||
|
||||
ASSERT_EQ(calibration.depth_camera_calibration.resolution_width, 0);
|
||||
ASSERT_EQ(calibration.depth_camera_calibration.resolution_width, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return k4a_test_commmon_main(argc, argv);
|
||||
|
|
Загрузка…
Ссылка в новой задаче