我想获取图像的宽度和高度,在 OpenCV 中如何实现?
例如:
Mat src = imread("path_to_image");
cout << src.width;
是吗?
您可以使用
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;
对于 python 中的 openCV 你也可以这样做:
img = cv2.imread('myImage.jpg')
height, width, channels = img.shape