如何在OpenCV中获取图像宽度和高度?
问题描述:
我想获得图像的宽度和高度,我怎么能在OpenCV中做到这一点?如何在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;
答
也为OpenCV的Python中,你可以这样做:
img = cv2.imread('myImage.jpg')
height, width, channels = img.shape
好,但OP是要求C++ – Petruza
是的,这是真的,但谷歌搜索的Python带来 你在这里。 – imoutidi