简体   繁体   中英

How to convert cv::Mat to dlib::array2d<uint16_t> ,and typedef unsigned short int uint16_t

I want to use depth frame data captured with realsensed435i in an algorithm. And,I need get data in type dlib::array2d<uint16_t> . But I can not get it directly.So, my approach is getting cv::Mat firstly and converting it to dlib::array2d<uint16_t> then . And I have tried the fllowing code ,but they do not work!

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));

when I run camke .. and make , it succeed. but when I run the executable binary files, it makes error.

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));

This works but the result is incorrect.

so, do you have any effective tips?

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

成功!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM