Mat和Dlib变量类型转换

Mat转matrix

cv::Mat frame = cv::imread("123.jpg");
matrix img;
assign_image(img,cv_image(frame));

值得注意的地方:matriximg不能放进vector<matrix>img,会报错!

array2d::bgr_pixel>转Mat

方法一:
dlib::array2d img_bgr;//使用dlib载入彩色的RGB图像      
dlib::load_image(img_bgr, "test_image.jpg");   
cv::Mat img = dlib::toMat(img_bgr);//这样图片不失真

方法二:

cv::Mat temp_Roi;
temp_Roi=imread("1.jpg");
array2d< bgr_pixel> img(temp_Roi.rows, temp_Roi.cols);
for (int i = 0; i < temp_Roi.rows; i++)
{
    for (int j = 0; j < temp_Roi.cols; j++)
    {
        img[i][j].blue = temp_Roi.at< cv::Vec3b>(i, j)[0];
        img[i][j].green = temp_Roi.at< cv::Vec3b>(i, j)[1];
        img[i][j].red = temp_Roi.at< cv::Vec3b>(i, j)[2];
    }
}点击打开链接

Mat转cv_image

cv::Mat img = cv::imread("test_image.jpg")  
dlib::cv_image dlib_img(img); 

Mat转cv_image

cv::Mat temp;
cv_image cimg(temp);

Opencv的rect转dlib的rect

dlib::rectangle dlibRect((long)opencvRect.tl().x, (long)opencvRect.tl().y, (long)opencvRect.br().x - 1, (long)opencvRect.br().y - 1);

Mat转dlib array2d

#include "dlib/opencv/cv_image.h"  //需要的头文件
cv::Mat ori_rgb_mat,photo_gray;
// RGB  
dlib::array2d dlib_image;  
dlib::assign_image(dlib_image, dlib::cv_image(ori_rgb_mat));  
// Gray  
//dlib::array2d dlibImageGray;  
//dlib::assign_image(dlibImageGray, dlib::cv_image(photo_gray));



你可能感兴趣的:(Dlib)