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

标签: dlib array2dOpenCV Matarray2d转Matdlib array2d转换OpenCV
1198人阅读 评论(1) 收藏 举报
分类:

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
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:414174次
    • 积分:4756
    • 等级:
    • 排名:第6778名
    • 原创:100篇
    • 转载:45篇
    • 译文:1篇
    • 评论:123条
    博客专栏
    最新评论