我将 Azure Kinect 相机连接到我的系统,从代码中我可以获取 IR 图像和深度图像,但彩色图像不起作用。我自己编译了 SDK,运行 k4aviewer.exe 时,我得到了同样的结果。IR + 深度相机工作,彩色相机只是空的。我得到的错误:
启动麦克风失败:无法打开设备!
无法启动麦克风监听器:无法打开设备!
然后我安装了官方 SDK,在那个 k4aviewer 中我得到了红外和彩色相机。但是当使用那个 lib 和 dll 编译时,我仍然一无所获。什么可能首先导致这个问题?我不能完全离开,因为我得到了深度数据。
主.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发现了一些非常相似的东西,但是我需要它在这个系统上工作。我该如何调试呢?