Day1 读取和显示图像

知识点:

读取图像 - imread

显示图像 - imshow

imread

头文件 #include <opencv2/imgcodecs.hpp>

函数原型

Mat cv::imread(const String & filename,
int flags = IMREAD_COLOR 
)

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

参数

filenameName of file to be loaded. 要读取文件的名称
flagsFlag that can take values of cv::ImreadModes 打开文件的方式

ImreadModes

Enumerator
IMREAD_UNCHANGED 

Python: cv.IMREAD_UNCHANGED

If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.

IMREAD_GRAYSCALE 

Python: cv.IMREAD_GRAYSCALE

If set, always convert image to the single channel grayscale image (codec internal conversion). 常用

IMREAD_COLOR 

Python: cv.IMREAD_COLOR

If set, always convert image to the 3 channel BGR color image. 常用

IMREAD_ANYDEPTH 

Python: cv.IMREAD_ANYDEPTH

If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.

IMREAD_ANYCOLOR 

Python: cv.IMREAD_ANYCOLOR

If set, the image is read in any possible color format.

IMREAD_LOAD_GDAL 

Python: cv.IMREAD_LOAD_GDAL

If set, use the gdal driver for loading the image.

IMREAD_REDUCED_GRAYSCALE_2 

Python: cv.IMREAD_REDUCED_GRAYSCALE_2

If set, always convert image to the single channel grayscale image and the image size reduced 1/2.

IMREAD_REDUCED_COLOR_2 

Python: cv.IMREAD_REDUCED_COLOR_2

If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.

IMREAD_REDUCED_GRAYSCALE_4 

Python: cv.IMREAD_REDUCED_GRAYSCALE_4

If set, always convert image to the single channel grayscale image and the image size reduced 1/4.

IMREAD_REDUCED_COLOR_4 

Python: cv.IMREAD_REDUCED_COLOR_4

If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.

IMREAD_REDUCED_GRAYSCALE_8 

Python: cv.IMREAD_REDUCED_GRAYSCALE_8

If set, always convert image to the single channel grayscale image and the image size reduced 1/8.

IMREAD_REDUCED_COLOR_8 

Python: cv.IMREAD_REDUCED_COLOR_8

If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.

IMREAD_IGNORE_ORIENTATION 

Python: cv.IMREAD_IGNORE_ORIENTATION

If set, do not rotate the image according to EXIF's orientation flag.

imshow

头文件#include <opencv2/highgui.hpp>

函数原型

void cv::imshow(const String & winname,
InputArray mat 
)
Python:
None=cv.imshow(winname, mat)

Parameters

winnameName of the window.   显示图片窗口的名称,自己命名
matImage to be shown.     要显示的图片

视频教程  bili教程直接点击

环境配置好以后,代码如下:

#include <opencv2\opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	Mat src = imread("D:/tool/opencv/opencv_tutorial_data-master/opencv_tutorial_data-master/images/hist_02.jpg");
	imshow("input", src);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值