microsoft / Azure-Kinect-Sensor-SDK

A cross platform (Linux and Windows) user mode SDK to read data from your Azure Kinect device.
https://Azure.com/Kinect
MIT License
1.5k stars 619 forks source link

depth camera question #1601

Closed ewwll closed 3 years ago

ewwll commented 3 years ago

Hello, when I use Azure kinect, I can’t open the depth camera but I can open the normal rgb camera. Why is this? and my code error: [ error ] : find_libusb_device(). Unable to find Container ID: {27425d48-b481-4111-a593-a89e9f44d4ca} [ error ] : usb_cmd_create(USB_DEVICE_COLOR_IMU_PROCESSOR, NULL_INDEX, container_id, &colormcu->usb_cmd) returned failure in colormcu_create() [ error ] : colormcu_create(container_id, &device->colormcu) returned failure in k4a_device_open() and my code: //#pragma comment(lib, "k4a.lib")

include

include <k4a/k4a.h>

include <k4arecord/record.h>

include <k4arecord/playback.h>

include < iostream>

include

include <opencv2/core/core.hpp>

include <opencv2\opencv.hpp>

include <opencv2/highgui/highgui.hpp>

include <k4a/k4a.hpp>

include < cstdlib>

include<opencv2/highgui.hpp>

include<opencv2/imgproc/imgproc.hpp>

include<core/core.hpp>

include

include

using namespace cv; using namespace std; int n = 0; string cname = "./rgb/color"; string dname = "./depth/depth";

cv::Mat color_frame; cv::Mat depth_frame;

void on_mouse(int event, int x, int y, int flags, void* ustc) { if (event == EVENT_LBUTTONDOWN) { cout <<"111"<< endl; Mat img1, img2; resize(color_frame, img1, Size(512, 512)); resize(depth_frame, img2, Size(512, 512)); imwrite(cname + to_string(n) + ".jpg", img1); imwrite(dname + to_string(n) + ".jpg", img2); n++; } }

int main() { k4a::capture capture; const uint32_t device_count = k4a::device::get_installed_count(); if (device_count == 0) { printf("No K4A devices found\n"); return 0; }

k4a::device device = k4a::device::open(K4A_DEVICE_DEFAULT);

k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL; 
config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
config.color_resolution = K4A_COLOR_RESOLUTION_1080P;
config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
config.camera_fps = K4A_FRAMES_PER_SECOND_30;
config.synchronized_images_only = true;

device.start_cameras(&config);

k4a::image rgbImage;
k4a::image depthImage;

time_t first, second;
first = time(NULL);

while (true)
{
    if (device.get_capture(&capture, std::chrono::milliseconds(0)))
    {
        rgbImage = capture.get_color_image();
        depthImage = capture.get_depth_image();

        color_frame = cv::Mat(rgbImage.get_height_pixels(), rgbImage.get_width_pixels(), CV_8UC4, rgbImage.get_buffer());
        depth_frame = cv::Mat(depthImage.get_height_pixels(), depthImage.get_width_pixels(), CV_16U, depthImage.get_buffer());

        depth_frame.convertTo(depth_frame, CV_8U, 1);

        cv::imshow("color", color_frame);
        cv::imshow("depth", depth_frame);

        //cv::setMouseCallback("color", on_mouse, 0);
        second = time(NULL);
        if (waitKey(1)=='q')
        {
            //cout << difftime(second, first) << endl;
            Mat img1, img2;
            cout << cname + to_string(n) +".jpg"<<endl;
            cout << dname + to_string(n) + ".jpg" << endl;
            resize(color_frame, img1, Size(512, 512));
            resize(depth_frame, img2, Size(512, 512));
            imwrite(cname + to_string(n) +".jpg", img1);
            imwrite(dname + to_string(n) + ".jpg",img2);
            n = n + 1;
        }

        color_frame.release();
        depth_frame.release();

        capture.reset();
        if (waitKey(1) == 27)
            break;
    }
}
cv::destroyAllWindows();
device.close();
return 0;

} But I use Azure Kinect ordinary rgb camera to read the video but there is no problem my code:

include <opencv2\opencv.hpp>

using namespace cv; int main() {

VideoCapture capture(0);

while (1)
{
    Mat frame;  
    capture >> frame;  
    imshow("show", frame); 
    waitKey(3);  
}
return 0;

}

VegetableWithChicken commented 3 years ago

set like this:

StartFragment-->NativeKinectDevice = k4a::device::open(DeviceId);
// Start the Camera and make sure the Depth Camera is Enabled
k4a_device_configuration_t deviceConfig = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL; deviceConfig.depth_mode = DepthMode;
deviceConfig.color_resolution = K4A_COLOR_RESOLUTION_1080P; deviceConfig.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
deviceConfig.wired_sync_mode = k4a_wired_sync_mode_t::K4A_WIRED_SYNC_MODE_STANDALONE; deviceConfig.synchronized_images_only = true;

//Read Image like this:
//Color
AzureColorImage = sensorCapture.get_color_image();
//Depth
AzureDepthImgae = sensorCapture.get_depth_image();