Opencv存图读图
生活随笔
收集整理的這篇文章主要介紹了
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存图读图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苏州新导_智慧养老解决方案_养老院解决方
- 下一篇: mysql desc select_数据