sarmad m sarmad m - 3 months ago 22
C++ Question

How to get image width and height in OpenCV?

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?

Answer

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;