Python 如何在 OpenCV 中获取图像的宽度和高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32971241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:33:26  来源:igfitidea点击:

How to get image width and height in OpenCV?

pythonc++opencv

提问by sarmad m

I want to get image width and height, how can I do that in OpenCV?

我想获得图像的宽度和高度,我该如何在 OpenCV 中做到这一点?

For example:

例如:

Mat src = imread("path_to_image");
cout << src.width;

Is that right?

那正确吗?

采纳答案by Miki

You can use rowsand cols:

您可以使用rowscols

cout << "Width : " << src.cols << endl;
cout << "Height: " << src.rows << endl;

or size():

size()

cout << "Width : " << src.size().width << endl;
cout << "Height: " << src.size().height << endl;

回答by Iraklis Moutidis

Also for openCV in python you can do:

同样对于python中的openCV,您可以执行以下操作:

img = cv2.imread('myImage.jpg')
height, width, channels = img.shape