我为使用array2d获取图像的dlib面部地标代码创建了dll,但我喜欢使用Mat读取图像并转换为array2d,因为dlib仅支持array2d。任何人都可以说如何将mat转换为array2d ??
答案 0 :(得分:7)
将 cv :: Mat 图像转换为 dlib :: array2d :
如果是BGR图像,您可以按照以下步骤操作:
dlib::array2d<dlib::bgr_pixel> dlibImage;
dlib::assign_image(dlibImage, dlib::cv_image<dlib::bgr_pixel>(cvMatImage));
而且,如果您有灰度图像,只需使用<unsigned char>
代替<bgr_pixel>
:
dlib::array2d<unsigned char> dlibImageGray;
dlib::assign_image(dlibImage, dlib::cv_image<unsigned char>(cvMatImageGray));
答案 1 :(得分:2)
首先将Mat转换为dlib的cv_image。然后使用dlib的assign_image(),您可以将cv_image转换为array2d。
答案 2 :(得分:1)
#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);