opencv Mat和Dlib变量类型转换

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));

 

©️2020 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值