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

我想得到图像的宽度和高度,我怎样才能做到这一点在 OpenCV?

例如:

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

是吗?

182792 次浏览

你可以使用 rowscols:

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;

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

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