I want to get image width and height, how can I do that in OpenCV?
For example:
Mat src = imread("path_to_image");
cout << src.width;
Is that right?
I want to get image width and height, how can I do that in OpenCV?
For example:
Mat src = imread("path_to_image");
cout << src.width;
Is that right?
You can use rows
and cols
:
cout << "Width : " << src.cols << endl;
cout << "Height: " << src.rows << endl;
or size()
:
cout << "Width : " << src.size().width << endl;
cout << "Height: " << src.size().height << endl;
or size
cout << "Width : " << src.size[1] << endl;
cout << "Height: " << src.size[0] << endl;
Also for openCV in python you can do:
img = cv2.imread('myImage.jpg')
height, width, channels = img.shape
img
object is of type <class 'numpy.ndarray'>
. If the image path is incorrect and you try to use that in cv2.imread
, it would give a WARNING not an error. Your program won't stop there!