dlib中的image和opencv中的image格式互转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kunyXu/article/details/78864522
    //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时颜色失真  

猜你喜欢

转载自blog.csdn.net/kunyXu/article/details/78864522