Home > other >  What's the definition of image size in OpenCV?
What's the definition of image size in OpenCV?

Time:12-28

What's the size

import cv2

img = cv2.imread('./imgs/img.png', cv2.IMREAD_COLOR)

print(img.shape[0], img.shape[1])  # 182 277
print(img.size)  # 151242

I thought img.size = img.width * img.width, but obviously wrong, check this example.

so, what's the definition of it?

CodePudding user response:

It's all about what language you're working in.

The Python interface to OpenCV uses numpy, and numpy arrays have different methods from cv::Mat (C ). size means different things then.

  • Python: OpenCV uses numpy arrays. .size tells you the number of elements in the array. That is the product of all values in .shape.

  • C : OpenCV uses its own cv::Mat. .size there is of type MatSize. It is roughly equivalent to .shape with numpy. Documentation indicates that it can also tell you the number of channels. It has an operator[] defined.

  • Related