126

cv2Python OpenCV (numpy) のラッパーで画像のサイズを取得する方法。以外にそれを行う正しい方法はありますかnumpy.shape()。これらの形式の寸法で取得するにはどうすればよいですか: (幅、高さ) リスト?

4

3 に答える 3

270

cv2 uses numpy for manipulating images, so the proper and best way to get the size of an image is using numpy.shape. Assuming you are working with BGR images, here is an example:

>>> import numpy as np
>>> import cv2
>>> img = cv2.imread('foo.jpg')
>>> height, width, channels = img.shape
>>> print height, width, channels
  600 800 3

In case you were working with binary images, img will have two dimensions, and therefore you must change the code to: height, width = img.shape

于 2013-09-30T15:37:37.307 に答える