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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Opencv存图读图

發布時間:2023/12/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Opencv存图读图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

一,存儲圖像

1,存儲 imwrite

2,編碼格式

3,圖片位深

二,讀取圖像

1,讀取 imread

2,讀取類型 ImreadModes


一,存儲圖像

1,存儲 imwrite

imwrite("D:/im2.jpg", image2);

第三個參數缺省了。

2,編碼格式

jpg是有損壓縮,png是無損壓縮,如果對圖片要求很高的,還是用png好一點。

3,圖片位深

32F類型的圖片,像這樣存下來之后會變成8U的,讀取之后也是8U的,

即使再轉換成32F的,也可能和原圖有差異。

二,讀取圖像

1,讀取 imread

string path = "D:/im2.jpg"; Mat image = imread(path, IMREAD_UNCHANGED); if (!image.data) {cout << "imread fail\n";return; }

第二個參數是ImreadModes類型的枚舉,表示讀取的通道數

返回的是一個Mat類型的對象。

成員data是uchar的指針,如果讀取失敗那么指針為空

2,讀取類型 ImreadModes

ImreadModes的源代碼:

enum ImreadModes {IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion).IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.};

-1 IMREAD_UNCHANGED 表示按照圖片本身的通道數

0 IMREAD_GRAYSCALE 表示灰度圖像,即單通道

1?IMREAD_COLOR 表示按照3通道

總結

以上是生活随笔為你收集整理的Opencv存图读图的全部內容,希望文章能夠幫你解決所遇到的問題。

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