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

How to get image width and height in OpenCV?

本文关键字:图像 高度 OpenCV      更新时间:2023-10-16

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

例如:

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

对吗?

您可以使用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