OpenCV:像素数与行数*列数

时间:2015-02-04 14:42:34

标签: python opencv pixel

我运行此代码:

import cv2
import numpy as np 

img_file='pokemon.jpg'
img=cv2.imread(img_file)  

# print total number of rows, columns and channels that are provided in the picture
print 'Image shape: ',img.shape # rows = 630, columns = 900

# now let us print the total number of pixels that the picture has 
print 'Number of pixels: ', img.size # 1701000
print 630*900 # 56700

为什么最后两个输出有所不同?列和行的数量不是表示在像素矩阵内组织的像素数吗?

1 个答案:

答案 0 :(得分:2)

感谢@beaker的评论,答案是:

  

对于多通道图像,列包含与子通道一样多的子列   频道数量。例如,在RGB颜色系统的情况下:

enter image description here

Documentation.