Dlib学习笔记:dlib array2d与 OpenCV Mat互转

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
 

阅读更多

扫码向博主提问

pan_jinquan

博客专家

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • 图像处理
  • AI人工智能
  • OpenCV
  • TensorFlow
  • Caffe
去开通我的Chat快问
版权声明:本文为博主原创文章,未经博主允许不得转载(pan_jinquan) https://blog.csdn.net/guyuealian/article/details/77101603
个人分类: OpenCV 图像处理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭