首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >相机不能捕捉到彩色图像

相机不能捕捉到彩色图像
EN

Stack Overflow用户
提问于 2020-11-10 22:25:30
回答 1查看 86关注 0票数 0

我将Azure Kinect摄像头连接到我的系统,从代码中我可以获取一张红外图像和一张深度图像,但彩色图像无法工作。我自己编译了SDK,当运行k4aviewer.exe时,我得到了同样的东西。红外线+深度相机工作,彩色相机只是empty.Errors我得到:

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

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

然后我安装了官方的SDK,在这个k4aviewer中我得到了红外和彩色摄像头。但是当使用该库和dll进行编译时,我仍然什么也得不到。首先,是什么导致了这个问题?我不能完全失控,因为我得到了深度数据。

main.cpp:

代码语言:javascript
复制
#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:

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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上发现了一些非常类似的东西,但是我需要它在这个系统上工作。我如何调试它呢?

EN

回答 1

Stack Overflow用户

发布于 2020-12-02 02:48:42

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64770775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档