相机未捕捉到彩色图像

问题描述

我将Azure Kinect相机连接到我的系统,并且可以通过代码获取IR图像和Depth图像,但是Color图像不起作用。我已经自己编译了SDK,并且在运行k4aviewer.exe时得到了同样的东西。红外+深度相机工作,彩色相机只是空的。我得到的错误是:

无法启动麦克风:无法打开设备!

无法启动麦克风监听器:无法打开设备!

然后我安装了官方的SDK,在那个k4aviewer中,我同时获得了红外和彩色相机。但是当使用该lib和dll进行编译时,我仍然什么也没得到。首先可能导致此问题的原因是什么?得到深度数据后,我不能完全放弃。

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();
}

注意:我在https://github.com/microsoft/Azure-Kinect-Sensor-SDK/issues/1237发现了一些非常相似的东西,但是后来我需要它才能在该系统上工作。我该如何调试?

解决方法

对于第一次捕获,超时可能太短。您也没有检查AzureKinect :: grab_images()的错误代码。错误日志中报告了什么?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...