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