【发布时间】:2016-01-03 10:42:17
【问题描述】:
我想获得图像的宽度和高度,我该如何在 OpenCV 中做到这一点?
例如:
Mat src = imread("path_to_image");
cout << src.width;
对吗?
【问题讨论】:
我想获得图像的宽度和高度,我该如何在 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
【讨论】: