opencv 显示图片

目录

opencv显示图片

imread,读取图片

 namedWindow,创建窗口

imshow,显示图片 

waitKey,等待窗口关闭

destroyAllWindows,销毁窗口


opencv显示图片

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv) {
	Mat src = imread("E://images//test.jpg");
	if (src.empty()) {
		printf("未能找到图片\n");
		return -1;
	}
	namedWindow("显示图片", WINDOW_AUTOSIZE);
	imshow("显示图片", src);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

imread,读取图片

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

参数一 filename类型const String& ,是图片的位置,不能直接复制图片的位置E:\images\test.jpg,应该将'\'转换为‘/’或“//”;

参数二 flags 类型int,图片加载类型

常用有

  • 默认为IMREAD_COLOR,加载彩色图片
  • IMREAD_UNCHANGED 原样加载,新版已废弃
  • IMREAD_GRAYSCALE转换为灰色图片
  • IMREAD_ANYDEPTH 加载原深度
  • IMREAD_ANYCOLOR 加载原颜色
-1IMREAD_UNCHANGED          If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.
0IMREAD_GRAYSCALE          If set, always convert image to the single channel grayscale image (codec internal conversion).
1IMREAD_COLOR              If set, always convert image to the 3 channel BGR color image.
2IMREAD_ANYDEPTH           If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
4IMREAD_ANYCOLOR           If set, the image is read in any possible color format.
8IMREAD_LOAD_GDAL          If set, use the gdal driver for loading the image.
16IMREAD_REDUCED_GRAYSCALE_2If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
17IMREAD_REDUCED_COLOR_2    If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
32IMREAD_REDUCED_GRAYSCALE_4If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
33IMREAD_REDUCED_COLOR_4    If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
64IMREAD_REDUCED_GRAYSCALE_8If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
65IMREAD_REDUCED_COLOR_8    If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
128IMREAD_IGNORE_ORIENTATION If set, do not rotate the image according to EXIF's orientation flag.

 namedWindow,创建窗口

void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);

 参数一winname类型const String& ,窗口名称

参数二flags类型flags,窗口类型

WINDOW_NORMAL     the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.
WINDOW_AUTOSIZE   the user cannot resize the window, the size is constrainted by the image displayed.
WINDOW_OPENGL     window with opengl support.
WINDOW_FULLSCREEN change the window to fullscreen.
WINDOW_FREERATIO  the image expends as much as it can (no ratio constraint).
WINDOW_KEEPRATIO  the ratio of the image is respected.
WINDOW_GUI_EXPANDEDstatus bar and tool bar
WINDOW_GUI_NORMAL old fashious way

imshow,显示图片 

void imshow(const String& winname, InputArray mat);

 参数一winname类型const String& ,窗口名称

参数二mat类型InputArray,显示图片

waitKey,等待窗口关闭

int waitKey(int delay = 0);

参数delay,等待用户按键时间,单位毫秒,在delay时间内用户按键或等待时间超过delay,窗口自动退出,0表示一直等待用户按键

destroyAllWindows,销毁窗口

void destroyAllWindows();

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值