我在 Python 模式下使用处理来加载图像并对其进行计算。总体思路是:
def setup():
global maxx, maxy
maxx = 0
maxy = 0
# load the image
global img
img = loadImage("img.jpg");
maxx = img.width
maxy = img.height
def draw():
image(img, 0, 0);
def mousePressed():
calc()
def calc():
height = int(img.height)
width = int(img.width)
print "width: " + `width`
print "height: " + `height`
print "width*height: " + `width*height`
# iterate over the input image
loadPixels()
print "length of pixels array: " + `len(pixels)`
# ... do stuff with the image
对于 1920x1200 左右的较小图像,“宽度 * 高度”和“像素阵列长度”是相同的。对于像 3025 × 2009 这样的大图像,像素阵列的长度要小得多。对于 3025 x 2009 的示例,差异是:
宽度 * 高度:6077225 像素阵列长度:3944600
任何想法可能会发生什么?