Mat转matrix<dlib::rgb_pixel>
cv::Mat frame = cv::imread("test.jpg");
matrix<dlib::rgb_pixel> img;
assign_image(img,cv_image<rgb_pixel>(frame));
array2d<dlib::bgr_pixel>转Mat
方法一:
dlib::array2d<dlib::bgr_pixel> img_bgr;//使用dlib载入彩色的RGB图像
dlib::load_image(img_bgr, "test.jpg");
cv::Mat img = dlib::toMat(img_bgr);
方法二:
cv::Mat temp_Roi;
temp_Roi=imread("test.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<rgb_pixel>
cv::Mat img = cv::imread("test.jpg")
dlib::cv_image<rgb_pixel> dlib_img(img);
Mat转cv_image<bgr_pixel>
cv::Mat temp = cv::imread("test.jpg");
dlib::cv_image<bgr_pixel> 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"
#include <opencv2/opencv.hpp>
// RGB彩色图,RGB类型有 rgb_pixel和bgr_pixel两种,dlib要想不失真的转到OpenCV中,应该使用bgr_pixel,因为OpenCV中的颜色也是以“B,G,R”通道顺序排列的。
cv::Mat ori_mat = cv::imread("test.jpg");
dlib::array2d<dlib::bgr_pixel> dlib_image;
dlib::assign_image(dlib_image, dlib::cv_image<dlib::bgr_pixel>(ori_mat));
// 灰度图
cv::Mat photo_gray = cv::imread("gray.jpg");
dlib::array2d<unsigned char> dlibImageGray;
dlib::assign_image(dlibImageGray, dlib::cv_image<unsigned char>(photo_gray));
来源:oschina
链接:https://my.oschina.net/u/4343506/blog/4311130