0

I connected a Azure Kinect Camera to my system, and from code I can grab an IR image and a Depth image, but the Color image is not working. I have compiled the SDK myself, and when running the k4aviewer.exe, I get the same thing. IR + Depth camera work, color camera is just empty.Errors I am getting:

Failed to start microphone: unable to open device!

Failed to start microphone listener: unable to open device!

 

I then installed the official SDK, in that k4aviewer I get both IR and color camera. But when compiling using that lib and dll, I still get nothing. What might cause this issue in the first place? I can't be totally off, as I get the depth data.

main.cpp:

#include "azure_camera.h"
#include <opencv2/opencv.hpp>

int main() {
    int count = global::getCameraCount();
    AzureKinect cam (0);
    cam.connectCamera();
    
    k4a_device_configuration_t config;// = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;

    config.camera_fps = K4A_FRAMES_PER_SECOND_30;
    config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
    config.color_resolution = K4A_COLOR_RESOLUTION_1080P;
    config.depth_delay_off_color_usec = 0;
    config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
    config.disable_streaming_indicator = false;
    config.subordinate_delay_off_master_usec = 0;
    config.synchronized_images_only = true;
    config.wired_sync_mode = K4A_WIRED_SYNC_MODE_STANDALONE;
        
    cam.startCamera(config);

    AzureKinect::Images m_images;

    cam.grab_images(false, m_images);
    
    {
        cv::imshow("Test Color", m_images.color);
        cv::imshow("Test Depth", m_images.depth);

        cv::waitKey(0);
    }

    cam.stopCamera();
    
    return 0;
}

AzureCamera.cpp:

#include "azure_camera.h"

AzureKinect::~AzureKinect() {
    device.close();
}

bool AzureKinect::connectCamera()
{
    try {
        device = k4a::device::open(index);
    }
    catch (...) {
        return false;
    }
    return true;
}

bool AzureKinect::startCamera(k4a_device_configuration_t _config)
{
    config = _config;
    try {
        device.start_cameras(&config);
    }
    catch(const k4a::error& e) {
        printf("Error occurred: %s", e.what());
        return false; 
    }    
    return true;
}

bool AzureKinect::stopCamera()
{
    device.stop_cameras();
    return true;
}
    
bool AzureKinect::grab_images(bool rectified, AzureKinect::Images& images)
{
    if (device.get_capture(&capture, std::chrono::milliseconds(1000)))
    {
        colorImage = capture.get_color_image();
        depthImage = capture.get_depth_image();
    }
    else
    {
        return false;
    }
    
    if (images.color.cols != colorImage.get_width_pixels() || images.color.cols != colorImage.get_height_pixels())
    {
        images.color = cv::Mat(colorImage.get_height_pixels(), colorImage.get_width_pixels(), CV_8UC4);
    }

    if (images.depth.cols != depthImage.get_width_pixels() || images.depth.cols != depthImage.get_height_pixels())
    {
        images.depth = cv::Mat(depthImage.get_height_pixels(), depthImage.get_width_pixels(), CV_16UC1);
    }

    std::memcpy(images.color.data, colorImage.get_buffer(), colorImage.get_size());
    std::memcpy(images.depth.data, depthImage.get_buffer(), depthImage.get_size());

    colorImage.reset();
    depthImage.reset();

    capture.reset();
    
    return true;
}
    
cv::Mat AzureKinect::get_calibration()
{
    return cv::Mat();
}

uint32_t global::getCameraCount()
{
    return k4a_device_get_installed_count();
}

AzureCamera.h

#include <k4a/k4a.hpp>
#include <opencv2/core.hpp>
#include <stdint.h>

class AzureKinect {
public:
    struct Images {
        cv::Mat color;
        cv::Mat depth;
    };

    AzureKinect(int id) : index(id), colorImage(nullptr), depthImage(nullptr) { }
    ~AzureKinect();

    bool connectCamera();
    bool startCamera(k4a_device_configuration_t _config);
    bool stopCamera();

    bool grab_images(bool rectified, AzureKinect::Images& images);

    cv::Mat get_calibration();
private:
    uint32_t index;
    k4a::device device;
    k4a::capture capture;
    k4a_device_configuration_t config;
    k4a::image colorImage;
    k4a::image depthImage;
};

namespace global {
    uint32_t getCameraCount();
}

Note: I found something really similar at https://github.com/microsoft/Azure-Kinect-Sensor-SDK/issues/1237 , but then I need it to work on this system. How can I debug this?

SinisterMJ
  • 3,425
  • 2
  • 33
  • 53

1 Answers1

1

The timeout might be too short for the first capture. You are also not checking the error code for AzureKinect::grab_images(). What is reported in the error log?

QM13
  • 61
  • 2