Azure Kinect获取相机内参

这篇具有很好参考价值的文章主要介绍了Azure Kinect获取相机内参。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

在采集点云数据时需要根据相机不同depth、color分辨率调整对应相机内参u0(px)、v0(py)、fx、fy,那么具体内参怎么获得呢?就跟随ludaner一起来看看吧。

其实Azure-Kinect-Sensor-SDK已经提供了example代码,只需编译运行即可:Azure-Kinect-Sensor-SDK/main.cpp at develop · microsoft/Azure-Kinect-Sensor-SDK · GitHubA cross platform (Linux and Windows) user mode SDK to read data from your Azure Kinect device. - Azure-Kinect-Sensor-SDK/main.cpp at develop · microsoft/Azure-Kinect-Sensor-SDKhttps://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/develop/examples/calibration/main.cpp

顺便把main.cpp代码贴出来

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
#include <k4a/k4a.h>
using namespace std;

static string get_serial(k4a_device_t device)
{
    size_t serial_number_length = 0;

    if (K4A_BUFFER_RESULT_TOO_SMALL != k4a_device_get_serialnum(device, NULL, &serial_number_length))
    {
        cout << "Failed to get serial number length" << endl;
        k4a_device_close(device);
        exit(-1);
    }

    char *serial_number = new (std::nothrow) char[serial_number_length];
    if (serial_number == NULL)
    {
        cout << "Failed to allocate memory for serial number (" << serial_number_length << " bytes)" << endl;
        k4a_device_close(device);
        exit(-1);
    }

    if (K4A_BUFFER_RESULT_SUCCEEDED != k4a_device_get_serialnum(device, serial_number, &serial_number_length))
    {
        cout << "Failed to get serial number" << endl;
        delete[] serial_number;
        serial_number = NULL;
        k4a_device_close(device);
        exit(-1);
    }

    string s(serial_number);
    delete[] serial_number;
    serial_number = NULL;
    return s;
}

static void print_calibration()
{
    uint32_t device_count = k4a_device_get_installed_count();
    cout << "Found " << device_count << " connected devices:" << endl;
    cout << fixed << setprecision(6);

    for (uint8_t deviceIndex = 0; deviceIndex < device_count; deviceIndex++)
    {
        k4a_device_t device = NULL;
        if (K4A_RESULT_SUCCEEDED != k4a_device_open(deviceIndex, &device))
        {
            cout << deviceIndex << ": Failed to open device" << endl;
            exit(-1);
        }

        k4a_calibration_t calibration;

        k4a_device_configuration_t deviceConfig = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
        deviceConfig.color_format = K4A_IMAGE_FORMAT_COLOR_MJPG;
        deviceConfig.color_resolution = K4A_COLOR_RESOLUTION_1080P;
        deviceConfig.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
        deviceConfig.camera_fps = K4A_FRAMES_PER_SECOND_30;
        deviceConfig.wired_sync_mode = K4A_WIRED_SYNC_MODE_STANDALONE;
        deviceConfig.synchronized_images_only = true;

        // get calibration
        if (K4A_RESULT_SUCCEEDED !=
            k4a_device_get_calibration(device, deviceConfig.depth_mode, deviceConfig.color_resolution, &calibration))
        {
            cout << "Failed to get calibration" << endl;
            exit(-1);
        }

        auto calib = calibration.depth_camera_calibration;

        cout << "\n===== Device " << (int)deviceIndex << ": " << get_serial(device) << " =====\n";
        cout << "resolution width: " << calib.resolution_width << endl;
        cout << "resolution height: " << calib.resolution_height << endl;
        cout << "principal point x: " << calib.intrinsics.parameters.param.cx << endl;
        cout << "principal point y: " << calib.intrinsics.parameters.param.cy << endl;
        cout << "focal length x: " << calib.intrinsics.parameters.param.fx << endl;
        cout << "focal length y: " << calib.intrinsics.parameters.param.fy << endl;
        cout << "radial distortion coefficients:" << endl;
        cout << "k1: " << calib.intrinsics.parameters.param.k1 << endl;
        cout << "k2: " << calib.intrinsics.parameters.param.k2 << endl;
        cout << "k3: " << calib.intrinsics.parameters.param.k3 << endl;
        cout << "k4: " << calib.intrinsics.parameters.param.k4 << endl;
        cout << "k5: " << calib.intrinsics.parameters.param.k5 << endl;
        cout << "k6: " << calib.intrinsics.parameters.param.k6 << endl;
        cout << "center of distortion in Z=1 plane, x: " << calib.intrinsics.parameters.param.codx << endl;
        cout << "center of distortion in Z=1 plane, y: " << calib.intrinsics.parameters.param.cody << endl;
        cout << "tangential distortion coefficient x: " << calib.intrinsics.parameters.param.p1 << endl;
        cout << "tangential distortion coefficient y: " << calib.intrinsics.parameters.param.p2 << endl;
        cout << "metric radius: " << calib.intrinsics.parameters.param.metric_radius << endl;

        k4a_device_close(device);
    }
}

static void calibration_blob(uint8_t deviceIndex = 0, string filename = "calibration.json")
{
    k4a_device_t device = NULL;

    if (K4A_RESULT_SUCCEEDED != k4a_device_open(deviceIndex, &device))
    {
        cout << deviceIndex << ": Failed to open device" << endl;
        exit(-1);
    }

    size_t calibration_size = 0;
    k4a_buffer_result_t buffer_result = k4a_device_get_raw_calibration(device, NULL, &calibration_size);
    if (buffer_result == K4A_BUFFER_RESULT_TOO_SMALL)
    {
        vector<uint8_t> calibration_buffer = vector<uint8_t>(calibration_size);
        buffer_result = k4a_device_get_raw_calibration(device, calibration_buffer.data(), &calibration_size);
        if (buffer_result == K4A_BUFFER_RESULT_SUCCEEDED)
        {
            ofstream file(filename, ofstream::binary);
            file.write(reinterpret_cast<const char *>(&calibration_buffer[0]), (long)calibration_size);
            file.close();
            cout << "Calibration blob for device " << (int)deviceIndex << " (serial no. " << get_serial(device)
                 << ") is saved to " << filename << endl;
        }
        else
        {
            cout << "Failed to get calibration blob" << endl;
            exit(-1);
        }
    }
    else
    {
        cout << "Failed to get calibration blob size" << endl;
        exit(-1);
    }
}

static void print_usage()
{
    cout << "Usage: calibration_info [device_id] [output_file]" << endl;
    cout << "Using calibration_info.exe without any command line arguments will display" << endl
         << "calibration info of all connected devices in stdout. If a device_id is given" << endl
         << "(0 for default device), the calibration.json file of that device will be" << endl
         << "saved to the current directory." << endl;
}

int main(int argc, char **argv)
{
    if (argc == 1)
    {
        print_calibration();
    }
    else if (argc == 2)
    {
        calibration_blob((uint8_t)atoi(argv[1]), "calibration.json");
    }
    else if (argc == 3)
    {
        calibration_blob((uint8_t)atoi(argv[1]), argv[2]);
    }
    else
    {
        print_usage();
    }

    return 0;
}

cmake编译不通过的添加或修改CMakeLists.txt为

## k4a
find_package(k4a 1.3.0 QUIET)
include_directories(${K4A_INCLUDE_DIRS})

add_executable(calibration_info main.cpp)
target_link_libraries(calibration_info PRIVATE k4a::k4a)

编译成功运行,可指定直接print输出或输出为json文件

修改以下代码输出不同分辨率:

deviceConfig.color_resolution = K4A_COLOR_RESOLUTION_1536P;
deviceConfig.depth_mode = K4A_DEPTH_MODE_WFOV_UNBINNED;

Azure Kinect提供的所有分辨率可在以下网页查看https://docs.microsoft.com/zh-cn/azure/Kinect-dk/hardware-specification

修改以下代码可选择输出color或depth相机分辨率

// color_camera_calibration, depth_camera_calibration
auto calib = calibration.color_camera_calibration; 

运行程序即可,po一个结果

Found 1 connected devices:

===== Device 0:  =====
resolution width: 2048
resolution height: 1536
principal point x: 1023.543701
principal point y: 777.486084
focal length x: 975.207458
focal length y: 974.770630
radial distortion coefficients:
k1: 0.205187
k2: -2.718986
k3: 1.783927
k4: 0.082789
k5: -2.509135
k6: 1.684085
center of distortion in Z=1 plane, x: 0.000000
center of distortion in Z=1 plane, y: 0.000000
tangential distortion coefficient x: 0.000927
tangential distortion coefficient y: -0.000091
metric radius: 0.000000

参考资料

​​​​​​​[1]https://github.com/microsoft/Azure-Kinect-Sensor-SDK/issues/1282#issuecomment-657684355文章来源地址https://www.toymoban.com/news/detail-412297.html

到了这里,关于Azure Kinect获取相机内参的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 基于多台azure kinects的点云采集、配准、相加

    本文采用多台Azure kinect实现了对人体的动态捕捉 如果你是刚接触kinect的小白,建议认真阅读Microsoft给出的官方文档 如果你打算自己开发azure kinect的程序,请参考官方的SDK手册 如果你想在win下配置azure kinect的开发环境,请参考我的上一篇文章 在linux下配置azure kinect会复杂一些

    2024年02月06日
    浏览(37)
  • 【Kinect】Ubuntu20.04 安装Azure Kinect Sensor

    本文主要记录Ubuntu20.04 安装Azure Kinect Sensor SDK Azure Kinect 人体跟踪 SDK官网 : https://learn.microsoft.com/zh-cn/azure/Kinect-dk/body-sdk-download Linux版本目前只支持 18.04 和 20.04 Azure Kinect 传感器 SDK 官网: https://learn.microsoft.com/zh-cn/azure/Kinect-dk/sensor-sdk-download Linux版本目前只支持 18.04 ,但也能

    2024年02月06日
    浏览(30)
  • Azure Kinect 使用记录 (一)

    20211111 - 占坑 20211115 - 添加vs编译内容 20220311 - k4abt_simple_3d_viewer 突然用不了了 因项目需要,得用Azure Kinect以及它的SDK进行开发,在这里记录下心得体会,不定时更新 1.0 k4abt_simple_3d_viewer 闪退 之前用着还好好的,突然就用不了了,表现情况是,双击 k4abt_simple_3d_viewer.exe ,出现

    2024年02月06日
    浏览(29)
  • kinect v2获取人体骨骼数据

    2024年02月08日
    浏览(19)
  • Azure Kinect 之 Note(一)

    Azure Kinect DK 是一款开发人员工具包,配有先进的AI 传感器,提供复杂的计算机视觉和语音模型。 Kinect 将深度传感器、空间麦克风阵列与视频摄像头和方向传感器整合成一体式的小型设备,提供多种模式、选项和软件开发工具包(SDK)。 https://learn.microsoft.com/zh-tw/azure/kinect-dk/h

    2024年02月16日
    浏览(33)
  • 史上最全Azure Kinect相关安装教程

    本教程旨在向无Azure Kinect开发经验的新手进行相关环境的安装。 https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/develop/docs/usage.md 安装 SDK 时,请记住要安装到的路径。 例如,“C:Program FilesAzure Kinect SDK 1.2”。 你将要在此路径中查找文章中参考的工具。此处建议按照默认位置安

    2024年02月07日
    浏览(30)
  • Azure Kinect 内置姿势识别 两种方法

    第一种方式:(适合单个姿势识别,多个场景多个姿势等复杂检测也可以实现,但是可能需要多创建几个类似脚本) 添加你要识别的内置姿势即可   KinectManager 增加用户时添加个调用   PoseDetector.Instance.UserWasAdded(userId, uidIndex); 随便放哪里,这里识别的 必须在面板上添加你

    2024年02月09日
    浏览(23)
  • Azure kinect (二)项目创建和环境配置

    在此之前,你需要安装Microsoft Visual Studio,本人先使用的是2019版本,后转用2022版本,如版本问题对项目创建和环境配置产生影响,欢迎咨询。 新建一个C++空项目 创建完成后,将是以下界面,已经熟悉Visual Studio的朋友们可跳过, 右键项目,进入属性设置 在链接器 -- 输入 —

    2024年02月10日
    浏览(23)
  • Azure Kinect微软摄像头Unity开发小结

    Azure Kienct是微软的代替Kinect的摄像头,用处其实蛮多的,最近做了这个的一些开发,总结一下。 如果只是当普通摄像头用的话,有集成显卡就行了。如果要用人体跟踪,至少要1050的独显。 微软摄像头代的东西还不少,可以建立点云地图,但是没试过。 下面是官方的SDK。后面

    2024年02月04日
    浏览(41)
  • Unity 结合 Azure Kinect 开发体感游戏教程

    本教程将介绍如何使用 Unity 和 Azure Kinect SDK 开发体感游戏。我们将重点介绍环境安装和手势的实现。 1. 准备工作 确保你已经拥有以下硬件和软件: Azure Kinect DK 设备 Windows 10 Unity 2020或更高版本 Visual Studio 2019或更高版本 2. 安装 Azure Kinect SDK 访问 Azure Kinect DK 官方页面 并下载

    2024年02月03日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包