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

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

问题描述:

我想获得图像的宽度和高度,我怎么能在OpenCV中做到这一点?如何在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; 

也为OpenCV的Python中,你可以这样做:

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

好,但OP是要求C++ – Petruza

+0

是的,这是真的,但谷歌搜索的Python带来 你在这里。 – imoutidi