Intel realsense T265pose配置C API

问题描述

我正在尝试使用 Intel realsense 和 T265 创建一个简单的姿势数据应用程序。 由于 C 示例数据库非常有限,我真的很难从这个 API 开始。

无论如何这是我的代码

/* Include the librealsense C header files */
#include <librealsense2/rs.h>
#include <librealsense2/h/rs_pipeline.h>
#include <librealsense2/h/rs_option.h>
#include <librealsense2/h/rs_frame.h>

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                     These parameters are reconfigurable                                        //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define STREAM          RS2_STREAM_ANY  
#define FORMAT          RS2_FORMAT_ANY 
#define WIDTH           0               
#define HEIGHT          0                 
#define FPS             0                
#define STREAM_INDEX    -1                 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void check_error(rs2_error* e)
{
    if (e)
    {
        printf("rs_error was raised when calling %s(%s):\n",rs2_get_Failed_function(e),rs2_get_Failed_args(e));
        printf("    %s\n",rs2_get_error_message(e));
        exit(EXIT_FAILURE);
    }
}

void print_device_info(rs2_device* dev)
{
    rs2_error* e = 0;
    printf("\nUsing device 0,an %s\n",rs2_get_device_info(dev,RS2_CAMERA_INFO_NAME,&e));
    check_error(e);
    printf("    Serial number: %s\n",RS2_CAMERA_INFO_SERIAL_NUMBER,&e));
    check_error(e);
    printf("    Firmware version: %s\n\n",RS2_CAMERA_INFO_FIRMWARE_VERSION,&e));
    check_error(e);
}

int main()
{
    rs2_error* e = 0;

    // Create a context object. This object owns the handles to all connected realsense devices.
    // The returned object should be released with rs2_delete_context(...)
    rs2_context* ctx = rs2_create_context(RS2_API_VERSION,&e);
    check_error(e);

    /* Get a list of all the connected devices. */
    // The returned object should be released with rs2_delete_device_list(...)
    rs2_device_list* device_list = rs2_query_devices(ctx,&e);
    check_error(e);

    int dev_count = rs2_get_device_count(device_list,&e);
    check_error(e);
    printf("There are %d connected RealSense devices.\n",dev_count);
    if (0 == dev_count)
        return EXIT_FAILURE;

    // Get the first connected device
    // The returned object should be released with rs2_delete_device(...)
    rs2_device* dev = rs2_create_device(device_list,&e);
    check_error(e);

    print_device_info(dev);

    // Create a pipeline to configure,start and stop camera streaming
    // The returned object should be released with rs2_delete_pipeline(...)
    rs2_pipeline* pipeline = rs2_create_pipeline(ctx,&e);
    check_error(e);

    // Create a config instance,used to specify hardware configuration
    // The returned object should be released with rs2_delete_config(...)
    rs2_config* config = rs2_create_config(&e);
    check_error(e);

    // Request a specific configuration
    rs2_config_enable_stream(config,STREAM,STREAM_INDEX,WIDTH,HEIGHT,FORMAT,FPS,&e);
    check_error(e);

    // Start the pipeline streaming
    // The retunred object should be released with rs2_delete_pipeline_profile(...)
    rs2_pipeline_profile* pipeline_profile = rs2_pipeline_start_with_config(pipeline,config,&e);
    check_error(e);

    while (1)
    {
        // This call waits until a new composite_frame is available
        // composite_frame holds a set of frames. It is used to prevent frame drops
        // The returned object should be released with rs2_release_frame(...)
        rs2_frame* frames = rs2_pipeline_wait_for_frames(pipeline,RS2_DEFAULT_TIMEOUT,&e);
        check_error(e);

        // Returns the number of frames embedded within the composite frame
        int num_of_frames = rs2_embedded_frames_count(frames,&e);
        check_error(e);

        int i;
        for (i = 0; i < num_of_frames; ++i)
        {
            // The retunred object should be released with rs2_release_frame(...)
            rs2_frame* frame = rs2_extract_frame(frames,i,&e);
            check_error(e);

            // Check if the given frame can be extended to depth frame interface
            // Accept only depth frames and skip other frames
            if (0 == rs2_is_frame_extendable_to(frame,RS2_EXTENSION_POSE,&e))
                continue;

            rs2_pose pose_data;
            rs2_pose_frame_get_pose_data(frame,&pose_data,&e);


            // Print the distance
            printf("data %f,%f,%f\n",pose_data.translation.x,pose_data.translation.y,pose_data.translation.z);

            rs2_release_frame(frame);
        }

        rs2_release_frame(frames);
    }

    // Stop the pipeline streaming
    rs2_pipeline_stop(pipeline,&e);
    check_error(e);

    // Release resources
    rs2_delete_pipeline_profile(pipeline_profile);
    rs2_delete_config(config);
    rs2_delete_pipeline(pipeline);
    rs2_delete_device(dev);
    rs2_delete_device_list(device_list);
    rs2_delete_context(ctx);

    return EXIT_SUCCESS;
}

这是我从控制台得到的:

有 2 个连接的实感设备。

使用设备 0,英特尔实感 T265 序列号:我的摄像头序列号 固件版本:0.2.0.951

调用时引发 rs_error rs2_pipeline_start_with_config(pipe:00000000021 90DB0,配置:0000000002190E30): 未连接设备

我总是在 rs2_pipeline_start_with_config 函数中失败。我尝试了不同的配置参数,但结果是一样的。 我还要提一下,我可以毫无问题地运行随 SDK 提供的 C++ 姿势示例。但我想让它使用 C 运行。

另外,我不知道为什么它可以识别具有相同序列号的两台相同设备,而我的 PC 上只有一台 T265。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)