Frame Differencing

I’m trying to build a frame differencing example similar to openMV camera.
As I’ve seen we don’t have the function alloc_extra_fb here so I couldn’t do it on memory yet, any plans of implementing it?

I’ve tried to port this following code but I got an illegal instruction on the line who calls “difference”

import sensor, image, os, time

TRIGGER_THRESHOLD = 5

BG_UPDATE_FRAMES = 50 # How many frames before blending.
BG_UPDATE_BLEND = 128 # How much to blend by... ([0-256]==[0.0-1.0]).

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.RGB565
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.set_auto_whitebal(False) # Turn off white balance.
clock = time.clock() # Tracks FPS.

# if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory

print("About to save background image...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.

filename = "/flash/bg.bmp"; #/

sensor.snapshot().save(filename)
print("Saved background image - Now frame differencing!")

triggered = False

frame_count = 0
while(True):
	clock.tick() # Track elapsed milliseconds between snapshots().
	img = sensor.snapshot() # Take a picture and return the image.

	frame_count += 1
	if (frame_count > BG_UPDATE_FRAMES):
		frame_count = 0
		img.blend(filename, alpha=(256-BG_UPDATE_BLEND))
		img.save(filename)
	# Replace the image with the "abs(NEW-OLD)" frame difference.
	print("1")

	img.difference(filename)

	print("2")

	hist = img.get_histogram()

	diff = hist.get_percentile(0.99).l_value() - hist.get_percentile(0.90).l_value()
	triggered = diff > TRIGGER_THRESHOLD

	print(clock.fps(), triggered) # Note: Your OpenMV Cam runs about half as fast while

Output

init i2c2
[MAIXPY]: find ov2640
True
About to save background image...
{"w":320, "h":240, "type"="rgb565", "size":153600}
Saved background image - Now frame differencing!
V (14325981972) SYSCALL: misaligned load recovered at 8000fda4. len:08,addr:000019f6,reg:06,data:0000000000000000,signed:1,float:0
                                                                                                                                  core dump: illegal instruction
Cause 0x0000000000000002, EPC 0x0000000000000000
reg[00](zero ) = 0x00000000801f5db0, reg[01](ra   ) = 0x0000000080053000
reg[02](sp   ) = 0x00000000802e8be8, reg[03](gp   ) = 0x00000000801ea3c0
reg[04](tp   ) = 0x0000000000000000, reg[05](t0   ) = 0x0000000000000000
reg[06](t1   ) = 0x0000000000000000, reg[07](t2   ) = 0x00000000000002e8
reg[08](s0/fp) = 0x00000000802e8ea0, reg[09](s1   ) = 0x00000000802f3ea0
reg[10](a0   ) = 0x00000000802e8ea0, reg[11](a1   ) = 0x00000000802e8e10
reg[12](a2   ) = 0x0000000000000002, reg[13](a3   ) = 0x00000000802e8df4
reg[14](a4   ) = 0xffffffffffff8005, reg[15](a5   ) = 0x00000000000019f6
reg[16](a6   ) = 0xfffffffffffffff7, reg[17](a7   ) = 0x0000000000000004
reg[18](s2   ) = 0x00000000802e8e80, reg[19](s3   ) = 0x00000000802e8e60
reg[20](s4   ) = 0x00000000803f3130, reg[21](s5   ) = 0x00000000000000b0
reg[22](s6   ) = 0x0000000080131f98, reg[23](s7   ) = 0x00000000802f5442
reg[24](s8   ) = 0x00000000802e9198, reg[25](s9   ) = 0x0000000000000000
reg[26](s10  ) = 0x0000000000000000, reg[27](s11  ) = 0x0000000000000000
reg[28](t3   ) = 0xfffffffffffffff1, reg[29](t4   ) = 0x0000000050000000
reg[30](t5   ) = 0x0000000000000000, reg[31](t6   ) = 0x0000000000000000
freg[00](ft0 ) = 0x0000000000000000(), freg[00]() = 0x0000000080121fe0()
freg[02](ft2 ) = 0x0000000000000000(), freg[00]() = 0x0000000080121ff0()
freg[04](ft4 ) = 0x0000000000000000(), freg[00]() = 0x0000000080122000()
freg[06](ft6 ) = 0x0000000000000000(), freg[00]() = 0x0000000080122010()
freg[08](fs0 ) = 0x0000000000000000(), freg[00]() = 0x0000000080122038()
freg[10](fa0 ) = 0x000001427fc00000(), freg[00]() = 0x0000000080122068()
freg[12](fa2 ) = 0x000000007fc00000(), freg[00]() = 0x0000000080122090()
freg[14](fa4 ) = 0x000000004bb71b00(), freg[-1073741824]() = 0x00000000801220a0()
freg[16](fa6 ) = 0x0000000000000000(), freg[00]() = 0x00000000801220b0()
freg[18](fs2 ) = 0x0000000000000000(), freg[00]() = 0x00000000801220d8()
freg[20](fs4 ) = 0x0000000000000000(), freg[00]() = 0x00000000801220e8()
freg[22](fs6 ) = 0x0000000000000000(), freg[00]() = 0x00000000801220f8()
freg[24](fs8 ) = 0x0000000000000000(), freg[00]() = 0x0000000080122108()
freg[26](fs10) = 0x0000000000000000(), freg[00]() = 0x0000000080122118()
freg[28](ft8 ) = 0x0000000000000000(), freg[00]() = 0x0000000080122140()
freg[30](ft10) = 0x0000000000000000(), freg[00]() = 0x0000000080122150()
W (14419329458) SYSCALL: sys_exit called by core 0 with 0x539

Thanks