import sensor, image, time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.set_auto_whitebal(False)
clock = time.clock() # Create a clock object to track the FPS.
clock.tick()# Update the FPS clock.
img = sensor.snapshot().mean(1)
template = image.Image("/template.bmp")
sensor.skip_frames(time = 2000)
diff = img.difference(template)在RGB565格式时是可以用的
你的template.bmp是什么格式的? img和template都是RGB565或者都是GRAYSCALE
@kidswong999 格式全是RGB565时是可以的,只是效果不太好!格式全都是灰度图时且大小相同,出现错误,大小和图像格式都是相同的!
什么错误?截个图?
效果还是挺好的

import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.snapshot().save("/template.bmp")
while(True):
img = sensor.snapshot()
diff = img.difference("/template.bmp")@kidswong999 我是将template.bmp保存到内存卡里面,然后再调用的,运行到images.difference时提示OSError: images not equal!