import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000) # Give the user time to get ready.
i=0
m=320
n=240
temp = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
img_past = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
img_now = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
kernel_edge = [1, 1, 1, \
1, -8, 1, \
1, 1, 1]
img_past=sensor.snapshot()
clock = time.clock()
while i < 1000:
# 获取当前灰度图
img_now = sensor.snapshot()
#当前灰度图归一化
#temp.normalize(0, 255)
# img_now.replace(temp)
#差分图的绝对值
img_now.save("temp3_withoutdifference/img_now"+str(i)+".bmp")
img_diff2 = img_now.difference(img_past)
img_diff2.morph(1, kernel_edge)
img_diff2.save("temp2/diff"+str(i)+".bmp")
i+=1
img_past.replace(img_now)
print(clock.fps())