Dlib学习笔记:dlib array2d与 OpenCV Mat互转
【尊重原创,转载请注明出处】 http://blog.csdn.net/guyuealian/article/details/77101603
在Dlib库中图像存储是使用array2d类型,而在OpenCV是使用Mat类型,Dlib中提供了#include <dlib/opencv.h>,可实现dlib array2d与 OpenCV Mat的互转。其中toMat对象可将dlib的图像转为OpenCV的Mat类型,而cv_image对象可将OpenCV的Mat类型转为dlib类型的图像。详见官网:http://dlib.net/imaging.html#rgb_pixel
//dlib::array2d is an image already, you can use it for any dlib's image functions//load image:dlib::array2d<dlib::rgb_pixel> img_rgb;//使用dlib载入彩色的RGB图像dlib::load_image(img_rgb, "test_image.jpg");//convert to greyscale:dlib::array2d<unsigned char> img_gray;//使用dlib载入灰度图像dlib::load_image(img_gray, "test_image.jpg");//或者dlib::assign_image(img_gray, img_rgb);//converto to OpenCV Image (cv::Mat):#include <dlib/opencv.h>#include <opencv2/opencv.hpp>cv::Mat img = dlib::toMat(img_rgb);//RGB图像cv::Mat img = dlib::toMat(img_gray);//灰度图像//get image from OpenCV:#include <dlib/opencv.h>#include <opencv2/opencv.hpp>cv::Mat img = cv::imread("test_image.jpg")dlib::cv_image<rgb_pixel> dlib_img(img); // only stores pointer, no deep copy//Documentation is here. There are a lot of well-documented examples, you should start from them. Special example about array2ddlib array2d转 OpenCV Mat时颜色失真
dlib array2d转 OpenCV Mat时,会出现颜色失真的现象,其解决方法是:http://blog.csdn.net/guyuealian/article/details/77482549