日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dlib学习笔记:解决dlib array2d转 OpenCV Mat时颜色失真

發布時間:2024/4/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dlib学习笔记:解决dlib array2d转 OpenCV Mat时颜色失真 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Dlib學習筆記:解決dlib array2d轉 OpenCV Mat時顏色失真

? 【尊重原創,轉載請注明出處】 http://blog.csdn.net/guyuealian/article/details/77482549
? ?在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?

?(1)dlib載入灰度圖像:

dlib::array2d<unsigned char> img_gray;//使用dlib載入灰度圖像 dlib::load_image(img_gray, "test_image.jpg");

? ?將dlib的灰度圖像轉為OpenCV Mat的圖像

#include <dlib/opencv.h> #include <opencv2/opencv.hpp> cv::Mat img = dlib::toMat(img_gray);//灰度圖

??若要將OpenCV Mat轉為dlib,可以這樣:

若要將OpenCV Mat轉為dlib,可以這樣: #include <dlib/opencv.h> #include <opencv2/opencv.hpp> cv::Mat img = cv::imread("test_image.jpg") dlib::cv_image<unsigned char> dlib_img(img); // only stores pointer, no deep copy

?(2)使用dlib載入彩色的RGB圖像:

dlib::array2d<dlib::rgb_pixel> img_rgb;//使用dlib載入彩色的RGB圖像 dlib::load_image(img_rgb, "test_image.jpg");

將dlib彩色圖像轉為OpenCV Mat類型的圖像:

cv::Mat img = dlib::toMat(img_rgb);

轉換后,圖像顯示會出現嚴重的顏色失真現象,如下圖所示,左圖是dlib顯示的img_rgb圖像,右圖是OpenCV顯示的img圖像

后來官網查了一下,原來dlib有多種圖像類型;http://dlib.net/imaging.html?

  • RGB
    • There are two RGB pixel types in dlib,?rgb_pixel?and?bgr_pixel. Each defines a 24bit RGB pixel type. The bgr_pixel is identical to rgb_pixel except that it lays the color channels down in memory in BGR order rather than RGB order and is therefore useful for interfacing with other image processing tools which expect this format (e.g.?OpenCV).
  • RGB Alpha
    • The?rgb_alpha_pixel?is an 8bit per channel RGB pixel with an 8bit alpha channel.
  • HSI
    • The?hsi_pixel?is a 24bit pixel which represents a point in the Hue Saturation Intensity (HSI) color space.
  • LAB
    • The?lab_pixel?is a 24bit pixel which represents a point in the CIELab color space.
  • Grayscale
    • Any built in scalar type may be used as a grayscale pixel type. For example, unsigned char, int, double, etc.

而RGB類型有?rgb_pixel和bgr_pixel兩種,細看文檔,才知道,dlib要想不失真的轉到OpenCV中,應該使用bgr_pixel,原因很簡單,OpenCV中的顏色也是以“B,G,R”通道順序排列的。

dlib::array2d<dlib::bgr_pixel> img_bgr;//使用dlib載入彩色的RGB圖像 dlib::load_image(img_bgr, "test_image.jpg"); cv::Mat img = dlib::toMat(img_bgr);

?

總結

以上是生活随笔為你收集整理的Dlib学习笔记:解决dlib array2d转 OpenCV Mat时颜色失真的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。