網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

imread函數|cv2

欄目: IT科技 / 發佈於: / 人氣:2.72W

cv2.imread函數是怎樣的呢?下面就讓我們一起來了解一下吧:

cv2一般來說也就是opencv,而imread爲image read的縮寫形式,簡單來說,imread函數通常是用於讀取圖像的。

當然,imread的函數原型主要有兩種,具體介紹如下:

1、imread c++原型

#include <opencv2/imgcodecs.hpp>

Mat cv::imread(const String & filename,

int flags = IMREAD_COLOR 

)

cv2.imread函數

2、imread python原型

Python:

retval=cv.imread(filename[, flags])

說明:根據上述可知,imread的函數原型還是很好理解的,比如其返回值,也就是Mat 類型,即返回讀取的圖像,讀取圖像失敗時會返回一個空的矩陣對象(Mat::data == NULL)。

參數說明:

filename  讀取的圖片檔案名,可使用相對路徑或是絕對路徑,但是必須要帶有完整的檔案副檔名(圖片格式後綴)

flags        一個讀取標記,用於選擇讀取圖片的方式,其默認值爲IMREAD_COLOR,flag值的設定一般是與用什麼顏色格式讀取圖片有關

cv2.imread函數 第2張

參考範例:

imread函數使用示例代碼:

 #include<iostream>

#include<opencv2/opencv.hpp>

using namespace cv;

using namespace std;

int main()

{

//read the image

Mat image = imread("./clock.jpg");

if (image.data != NULL)

{

/ow the image

imshow("clock", image);

waitKey(0);

}

else

{

cout << "can&apos;t openc the file!" << endl;

getchar();

}

return 0;