栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

opencv 显示图片

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

opencv 显示图片

目录

opencv显示图片

imread,读取图片

 namedWindow,创建窗口

imshow,显示图片 

waitKey,等待窗口关闭

destroyAllWindows,销毁窗口


opencv显示图片
#include 

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:imagestest.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();

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1001882.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号