Average of 4 pictures

Hello ,
I have a Cam M7.

I’m trying to develop a program that can create a picture which is the average of 4 other pictures .
The Idea I had is to take 5 pictures, and modify the fifth one in order to get the average ( by adding pixels)

The program is as follows :

Untitled - By: marc - mer. avr. 18 2018

import sensor, image, time, pyb

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(2000)

clock = time.clock()

L = 320
l = 240


img1 = sensor.snapshot()

img2 = sensor.snapshot()
img3 = sensor.snapshot()
img4 = sensor.snapshot()
img_average = sensor.snapshot()

for i in range(L*l):
img_average = ( ( img1 + img2 + img3 + img4 ) // 4 )

img1.save("/Image1")
img2.save("/Image2")
img3.save("/Image3")
img4.save("/Image4")

img_average.save("/Image_Average")

But I noticed that it is not possible to declare 5 Image objects by using sensor.snapshot : It’s like I have one image object instead of 5.


Is there any other way to do that ?

Best regards

Hi, please use this:

http://docs.openmv.io/library/omv.sensor.html#sensor.sensor.alloc_extra_fb

Just alloc the frame buffer and then use the blend method to blend images into the frame buffer. For examples, see the in memory frame differencing scripts.

Note that the system only has one frame buffer normally… I.e. the next snapshot overwrites the first one.

It works. Thank you very much !