Azure Kinect SDK相机配准
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include <iostream> #include <chrono> #include <cmath> #include <iostream> #include <vector> #include <memory> #include <condition_variable> #include <opencv2/opencv.hpp> #include <string> #include <fstream> #include <sstream> #include <algorithm> #include "mot.h" #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <thread> #include <dirent.h> #include <k4a/k4a.hpp> #include <k4a/k4atypes.h> #define COLOR_NUM 18 /*---- k4a相关声明 ----*/ k4a::device device = k4a::device::open(K4A_DEVICE_DEFAULT); k4a::capture capture; k4a::image rgbImage; k4a::image depthImage; k4a::image transformed_depthImage; cv::Mat cv_depth; cv::Mat cv_depth_8U; cv::Mat frame_depth; Mat cv_rgbImage_with_alpha; Mat cv_rgbImage_no_alpha; condition_variable con_v; bool ready = false ; mutex mtx; Mat frame_line; Mot mot; Rect last_rect; vector<Point> line_vec; Rect result; Mat frame; void get_img() { const uint32_t device_count = k4a::device::get_installed_count(); cout << "device_count : " << device_count << endl; 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_720P; config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED; //config.depth_mode = K4A_DEPTH_MODE_WFOV_2X2BINNED; config.synchronized_images_only = true ; device.start_cameras(&config); k4a::calibration k4aCalibration = device.get_calibration(config.depth_mode, config.color_resolution); // Get the camera calibration for the entire K4A device, which is used for all transformation functions. k4a::transformation k4aTransformation = k4a::transformation(k4aCalibration); cout << "--------- 1 ----------" << endl; while (1) { //cap >> frame; if (device.get_capture(&capture)) { rgbImage = capture.get_color_image(); depthImage = capture.get_depth_image(); cv_rgbImage_with_alpha = cv::Mat(rgbImage.get_height_pixels(), rgbImage.get_width_pixels(), CV_8UC4, ( void *) rgbImage.get_buffer()); cv::cvtColor(cv_rgbImage_with_alpha, cv_rgbImage_no_alpha, cv::COLOR_BGRA2BGR); transformed_depthImage = k4aTransformation.depth_image_to_color_camera(depthImage); cv_depth = cv::Mat(transformed_depthImage.get_height_pixels(), transformed_depthImage.get_width_pixels(), CV_16U, ( void *) transformed_depthImage.get_buffer(), static_cast < size_t >(transformed_depthImage.get_stride_bytes())); normalize(cv_depth, cv_depth_8U, 0, 256 * 256, NORM_MINMAX); cout << "rgbImage.size() : " << cv_rgbImage_no_alpha.size() << endl; cout << "cv_depth_8U.size() : " << cv_depth_8U.size() << endl; //cv_depth_8U.convertTo(cv_depth, CV_8U, 1); } frame = cv_rgbImage_no_alpha.clone(); frame_depth = cv_depth_8U.clone(); imshow( "rgb" , frame); imshow( "depth" , frame_depth); waitKey(1); } } int main() { get_img(); return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!