How to convert mat to array2d<rgb_pixel>?

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

I created dll for the dlib face landmark code there used array2d to get the image, but i like to read an image using Mat and to convert to array2d because dlib supports only array2d. Can any one say how to convert mat to array2d ??

回答1:

Convert a cv::Mat image to dlib::array2d:

In case of a BGR image, you can follow this:

dlib::array2d<bgr_pixel> dlibImage; dlib::assign_image(dlibImage, dlib::cv_image<bgr_pixel>(cvMatImage)); 

And, if you have a grayscale image, simply use <unsigned char> instead of <bgr_pixel>:

dlib::array2d<unsigned char> dlibImageGray; dlib::assign_image(dlibImage, dlib::cv_image<unsigned char>(cvMatImageGray)); 


回答2:

Firstly convert the Mat to cv_image of dlib. Then using the assign_image() of dlib you can convert the cv_image to array2d.



回答3:

#include "opencv2/core/core_c.h" // shame, but needed for using dlib #include <dlib/image_processing.h> #include <dlib/opencv/cv_image.h>  dlib::shape_predictor sp; dlib::deserialize(path_to_landmark_model) >> sp;  cv::Rect r; cv::Mat I; dlib::rectangle rec(r.x, r.y, r.x+r.width, r.y+r.height); dlib::full_object_detection shape = sp(dlib::cv_image<uchar>(I), rec); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!