close

How to get image width and height in OpenCV?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to get image width and height in OpenCV in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to get image width and height in OpenCV?

  1. How to get image width and height in OpenCV?

    Also for openCV in python you can do:
    img = cv2.imread('myImage.jpg') height, width, channels = img.shape

  2. image width and height in OpenCV

    Also for openCV in python you can do:
    img = cv2.imread('myImage.jpg') height, width, channels = img.shape

Method 1

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;

Method 2

Also for openCV in python you can do:

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

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read