如何在OpenCV中获取图像的宽度和高度? [重复]

问题描述 投票:0回答:2

我想获取图像的宽度和高度,在 OpenCV 中如何实现?

例如:

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

是吗?

python c++ opencv
2个回答
129
投票

您可以使用

rows
cols
:

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

size()
:

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

size

cout << "Width : " << src.size[1] << endl;
cout << "Height: " << src.size[0] << endl;

103
投票

对于 python 中的 openCV 你也可以这样做:

img = cv2.imread('myImage.jpg')
height, width, channels = img.shape 
© www.soinside.com 2019 - 2024. All rights reserved.