Reputation: 79
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 ??
Upvotes: 4
Views: 14079
Reputation: 1343
Convert a cv::Mat image to dlib::array2d:
In case of a BGR image, you can follow this:
dlib::array2d<dlib::bgr_pixel> dlibImage;
dlib::assign_image(dlibImage, dlib::cv_image<dlib::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(dlibImageGray, dlib::cv_image<unsigned char>(cvMatImageGray));
Upvotes: 8
Reputation:
Firstly convert the Mat to cv_image of dlib. Then using the assign_image() of dlib you can convert the cv_image to array2d.
Upvotes: 2
Reputation: 39796
#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);
Upvotes: 1