首页 > 解决方案 > 如何将 cv::Mat 转换为 dlib::array2d, 和 typedef unsigned short int uint16_t

问题描述

我想在算法中使用用 realsensed435i 捕获的深度帧数据。而且,我需要获取 type 中的数据dlib::array2d<uint16_t>。但我不能直接得到它。所以,我的方法是cv::Mat先获取,然后将其转换为dlib::array2d<uint16_t>。我已经尝试了以下代码,但它们不起作用!

case1: dlib::assign_image(node.im, dlib::cv_image<uint16_t> (settings.inputMat));

case2: dlib::assign_image(node.im, dlib::cv_image< unsigned char >(settings.inputMat));

当我运行camke ..and时make,它成功了。但是当我运行可执行二进制文件时,它会出错。

case1:hewenhui@hewenhui-Inspiron-7590:~/pre_PSLAM/D-KHT-master/bin$ ./testlib 

**************************** FATAL ERROR DETECTED ****************************

Error detected at line 36.
Error detected in file /usr/local/include/dlib/opencv/cv_image.h.
Error detected in function dlib::cv_image<pixel_type>::cv_image(const cv::Mat&) [with pixel_type = short unsigned int].

Failing expression was img.depth() == cv::DataType<typename pixel_traits<pixel_type>::basic_pixel_type>::depth && img.channels() == pixel_traits<pixel_type>::num.
The pixel type you gave doesn't match pixel used by the open cv Mat object.
     img.depth():    0
     img.cv::DataType<typename pixel_traits<pixel_type>::basic_pixel_type>::depth: 2
     img.channels(): 3
     img.pixel_traits<pixel_type>::num: 1

******************************************************************************

已放弃 (核心已转储)

case2:
**************************** FATAL ERROR DETECTED ****************************

Error detected at line 36.
Error detected in file /usr/local/include/dlib/opencv/cv_image.h.
Error detected in function dlib::cv_image<pixel_type>::cv_image(const cv::Mat&) [with pixel_type = short unsigned int].

Failing expression was img.depth() == cv::DataType<typename pixel_traits<pixel_type>::basic_pixel_type>::depth && img.channels() == pixel_traits<pixel_type>::num.
The pixel type you gave doesn't match pixel used by the open cv Mat object.
     img.depth():    0
     img.cv::DataType<typename pixel_traits<pixel_type>::basic_pixel_type>::depth: 2
     img.channels(): 3
     img.pixel_traits<pixel_type>::num: 1

******************************************************************************

已放弃 (核心已转储)

case3: dlib::assign_image(node.im, dlib::cv_image<dlib::bgr_pixel>(settings.inputMat));

这有效,但结果不正确。

那么,你有什么有效的技巧吗?

标签: c++opencv3.0dlibmatrealsense

解决方案


 dlib::assign_image(node.im, dlib::cv_image<ushort>(settings.inputMat));

成功!


推荐阅读