【发布时间】:2015-05-21 00:23:45
【问题描述】:
我为dlib 面部地标代码创建了dll,使用array2d 来获取图像,但我喜欢使用Mat 读取图像并转换为array2d,因为dlib 仅支持array2d。谁能说如何将 mat 转换为 array2d ??
【问题讨论】:
标签: c++ opencv image-processing rgb mat
我为dlib 面部地标代码创建了dll,使用array2d 来获取图像,但我喜欢使用Mat 读取图像并转换为array2d,因为dlib 仅支持array2d。谁能说如何将 mat 转换为 array2d ??
【问题讨论】:
标签: c++ opencv image-processing rgb mat
#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);
【讨论】:
dlib::cv_image<uchar>(Mat) 。查看最后一行代码。
首先将 Mat 转换为 dlib 的 cv_image。然后使用 dlib 的 assign_image() 可以将 cv_image 转换为 array2d。
【讨论】:
将 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(dlibImageGray, dlib::cv_image<unsigned char>(cvMatImageGray));
【讨论】: