当前位置:懂科普 >

IT科技

> cv2.imread函数

cv2.imread函数

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;

  • 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/itkeji/3mowrx.html