AZURE kinect 深度相机配置ubuntu16.04

1.升级cmake

// Download and extract cmake 3.14.5
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v3.14/cmake-3.14.5.tar.gz
tar -xzvf cmake-3.14.5.tar.gz
cd cmake-3.14.5/
//Install extracted source
./bootstrap
make -j4
sudo make install
cmake --version

sudo apt-get install jack-tools

2.安装ninja

sudo apt install ninja-build 

3.下载sdk

// 下载Azure Kinect release、1.1.1 版
gitclone -b v1.1.1 https://github.com/microsoft/Azure-Kinect-Sensor-SDK.git

下载relaese 1.1.1是因为目前官方还未提供libdepthengine.so.2.0库文件。
libdepthengine.so.1.0下载地址:
https://download.csdn.net/download/weixin_41628710/11484674
下载libdepthengine.so.1.0后, 放置/usr/lib/x86_64-linux-gnu/文件夹中
 

4.编译安装

mkdir build && cd build
cmake .. -GNinja
ninja
sudo ninja install

 5.编译完成开启k4aviewer无法获取深度视频流,可尝试以下解决方案

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get upgrade libstdc++6

下载relaese 1.1.1是因为目前官方还未提供libdepthengine.so.2.0库文件。
libdepthengine.so.1.0下载地址:
https://download.csdn.net/download/weixin_41628710/11484674
下载libdepthengine.so.1.0后, 放置/usr/lib/x86_64-linux-gnu/文件夹中

2下载libdepthengine.so.文件

下载地址为:

https://packages.microsoft.com/ubuntu/18.04/prod/pool/main/libk/

想要去掉管理员权限也能启动:
进入Azure Kinect sdk 源码根目录中 scripts 文件夹,复制99-k4a.rules文件至/etc/udev/rules.d/

sudo ./script/bootstrap-ubuntu.sh. 确保这些依赖都成功安装.

另一种方法是,直接在https://github.com/lemenkov/libyuv.gitgit clone下来,并将clone下来的libyuv文件夹改名为src,放到extern/libyuv/里。

然后在。gitmodules删除libyuv的下载

6.测试

在build文件下

sudo ./bin/k4aviewer

 

7.c++ 代码获取

#include <stdio.h>
#include <stdlib.h>
#include <k4a/k4a.h>
#include <opencv2/opencv.hpp>

int main(int argc, char **argv)
{
    int returnCode = 1;
    k4a_device_t device = NULL;
    const int32_t TIMEOUT_IN_MS = 1000;
    int captureFrameCount;
    k4a_capture_t capture = NULL;

  

   std::cout<<"d1"<<std::endl;

    uint32_t device_count = k4a_device_get_installed_count();

    if (device_count == 0)
    {
        printf("No K4A devices found\n");
        return 0;
    }

    if (K4A_RESULT_SUCCEEDED != k4a_device_open(K4A_DEVICE_DEFAULT, &device))
    {
        printf("Failed to open device\n");
        return 0;
    }
    std::cout<<"d2"<<std::endl;
    k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
    config.color_format = K4A_IMAGE_FORMAT_COLOR_MJPG;
    config.color_resolution = K4A_COLOR_RESOLUTION_2160P;
    config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
    config.camera_fps = K4A_FRAMES_PER_SECOND_30;

    if (K4A_RESULT_SUCCEEDED != k4a_device_start_cameras(device, &config))
    {
        printf("Failed to start device\n");
        return 0;
    }
    cv::Mat cv_rgbImage_with_alpha;
    cv::Mat cv_rgbImage_no_alpha,cv_irImage_8U,cv_depth_8U;
    std::cout<<"d3"<<std::endl;
    while (1)
    {
       k4a_image_t depthImage = NULL, colorImage = NULL, irImage = NULL;
       switch (k4a_device_get_capture(device, &capture, TIMEOUT_IN_MS))
        {
        case K4A_WAIT_RESULT_SUCCEEDED:
            break;
        case K4A_WAIT_RESULT_TIMEOUT:
            printf("Timed out waiting for a capture");
            continue;
            break;
        case K4A_WAIT_RESULT_FAILED:
            printf("Failed to read a capture");
            goto Exit;
        }
       // std::cout<<"d3"<<std::endl;
        cv::Mat color;
		colorImage = k4a_capture_get_color_image(capture);
		// if(colorImage)
		// {
        //      std::cout<<"d5"<<std::endl;
		// 	int width = k4a_image_get_width_pixels(colorImage);
		// 	int height = k4a_image_get_height_pixels(colorImage);
		// 	color = cv::Mat(cv::Size(width, height), CV_8UC4);
		// 	memcpy(color.data, (void*)k4a_image_get_buffer(colorImage), width * height * 4);
        //     std::cout<<"dd"<<std::endl;
		// }
		
		cv::Mat depth;
		depthImage = k4a_capture_get_depth_image(capture);
        if (depthImage)
        {
			int width = k4a_image_get_width_pixels(depthImage);
			int height = k4a_image_get_height_pixels(depthImage);
			depth = cv::Mat(cv::Size(width, height), CV_16UC1);
			memcpy(depth.data, (void*)k4a_image_get_buffer(depthImage), width * height * sizeof(int16_t));
            depth.convertTo(cv_depth_8U, CV_8U, 100 );
            cv::imshow("depth",cv_depth_8U);
           
        }
		
       
		cv::Mat IR_left, IR_right;
      
        irImage = k4a_capture_get_ir_image(capture);
        if (irImage != NULL)
        {
            //std::cout<<"d5"<<std::endl;
            int width = k4a_image_get_width_pixels(irImage);
            int height = k4a_image_get_height_pixels(irImage);
            cv::Mat IR_left = cv::Mat(cv::Size(width, height), CV_16UC1);
            memcpy(IR_left.data, (void*)k4a_image_get_buffer(irImage), width * height * sizeof(int16_t));
            //cv::Mat  cv_irImage = cv::Mat(height, width, CV_16U, (void*)k4a_image_get_buffer(irImage), width * height * sizeof(int16_t));
			IR_left.convertTo(cv_irImage_8U, CV_8U, 1 );
            cv::imshow("iii",cv_irImage_8U);
            if(cv::waitKey(10)==27)
                break;

        }
        
  
 
        
        if (colorImage)
            k4a_image_release(colorImage);
        if (depthImage)
            k4a_image_release(depthImage);
        if(irImage)
            k4a_image_release(irImage);
        if(capture)
            k4a_capture_release(capture);
        
        cv::waitKey(2);
    }

    returnCode = 0;
Exit: 
    if (device != NULL)
    {
        k4a_device_close(device);
    }

    return returnCode;
}

cmakelists.txt


cmake_minimum_required(VERSION 2.8)
set(k4a_DIR /usr/local/lib/cmake) 

project(WDKinectDKDemo)

find_package(k4a REQUIRED)

find_package(OpenCV REQUIRED)
 

include_directories( ${CMAKE_CURRENT_LIST_DIR} )
include_directories( ${OpenCV_INCLUDE_DIRS} )
 

add_executable(
	azureCapture 
	main_demo_Linux.cpp 
)

target_link_libraries(azureCapture PRIVATE k4a::k4a ${OpenCV_LIBS})
 
 

set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
 
 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值