logo

调用difference函数问题

2018-06-01 09:28
I
_3gxu
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格式时是可以用的

2018-06-01 10:57
I
网红小智智 星瞳科技

你的template.bmp是什么格式的? img和template都是RGB565或者都是GRAYSCALE

2018-06-01 11:13
I
_3gxu

@kidswong999 格式全是RGB565时是可以的,只是效果不太好!格式全都是灰度图时且大小相同,出现错误,大小和图像格式都是相同的!

2018-06-01 11:24
I
网红小智智 星瞳科技

什么错误?截个图?

I
网红小智智 星瞳科技

效果还是挺好的

d5a413cc-5612-4368-8ecc-e5208041b91f.gif
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")
2018-06-01 11:49
I
_3gxu

@kidswong999 我是将template.bmp保存到内存卡里面,然后再调用的,运行到images.difference时提示OSError: images not equal!