I would like to get the Image size in python,as I do it with c++.
int w = src->width; printf("%d", 'w');
open() is used to open the image and then . width and . height property of Image are used to get the height and width of the image.
When working with OpenCV Python, images are stored in numpy ndarray. To get the image shape or size, use ndarray. shape to get the dimensions of the image. Then, you can use index on the dimensions variable to get width, height and number of channels for each pixel.
Using openCV and numpy it is as easy as this:
import cv2 img = cv2.imread('path/to/img',0) height, width = img.shape[:2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With