Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image size (Python, OpenCV)

I would like to get the Image size in python,as I do it with c++.

int w = src->width; printf("%d", 'w'); 
like image 898
Andrea Diaz Avatar asked Oct 23 '12 14:10

Andrea Diaz


People also ask

How do I get the size of an image in Python?

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.

What is image size in OpenCV?

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.


1 Answers

Using openCV and numpy it is as easy as this:

import cv2  img = cv2.imread('path/to/img',0) height, width = img.shape[:2] 
like image 147
cowhi Avatar answered Sep 20 '22 11:09

cowhi