Find displacement on M4

Dear OpenMV team,

recently I came back to your great project, looking for fast implementation of optical flow. Find_displacement() function was looking promising, so I grab “old” M4 board laying around from couple of years.
According to: Finding translation and rotation using M4 - OpenMV Products - OpenMV Forums you have dropped support for M4, which in my opinion is slightly disappointing, so I decide to check if it is possible to run find_displacement() with all its dependencies on my old board until waiting for newly purchased couple of M7.

Getting deeper in your implementation, admire your work of clean coding. Although there are clean definitions of used modules, I would suggest following same concept for all used / unused modules, so slightly more advanced user can decide which module to use and fit even on “restricted” space revisions.

I have found that some math functions used by find_displacement() are in apriltags.c behind definition #define IMLIB_ENABLE_APRILTAGS, so probably not best place for those…
Finally find_displacement() works satisfactory on M4 board achieving approx. 25FPS on B64X64.

I am attaching couple of rough modifications if anyone is interested in running find_displacement() on older M4 boards.

apriltag_OPENMV2.c (433 KB)
imlib_config_OPENMV2.h (2.46 KB)
py_image_OPENMV2.c (266 KB)
Rename and replace according files for OPENMV2 in:
/src/omv/boards/OPENMV2/imlib_config.h
/src/omv/img/apriltag.c
/src/omv/py/py_image.c

Running fft analysis for finding translation, rotation, scale is pretty advanced approach, although running fft on small bins is inaccurate to achieve acceptable accuracy.
For my purposes I have implemented new function compute_flow() which gives better results for robust and fast optical flow estimation at approx. 90FPS on M7.
If anyone is interested, I can share how to include new functions into micropython and OpenMV (it would be great if there is such tutorial)

Keep up good work!

Cheers

According to: > Finding translation and rotation using M4 - OpenMV Products - OpenMV Forums > you have dropped support for M4, which in my opinion is slightly disappointing,

We didn’t, we still support the M4 in every new firmware release. However we can only fix bugs for the M4, we can’t add any new feature because we ran out of FLASH and RAM. We’re Not doing this on purpose, the F7 and H7 are selling just fine, it’s just the M4 limits.

Getting deeper in your implementation, admire your work of clean coding. Although there are clean definitions of used modules, I would suggest following same concept for all used / unused modules, so slightly more advanced user can decide which module to use and fit even on “restricted” space revisions.
I have found that some math functions used by find_displacement() are in apriltags.c behind definition #define IMLIB_ENABLE_APRILTAGS, so probably not best place for those…

I agree, that’s what I’m going for eventually, to make all imlib configurable and generic. If you’d like to send PRs to refactor imlib code you’re welcome.

Running fft analysis for finding translation, rotation, scale is pretty advanced approach, although running fft on small bins is inaccurate to achieve acceptable accuracy.
For my purposes I have implemented new function compute_flow() which gives better results for robust and fast optical flow estimation at approx. 90FPS on M7.
If anyone is interested, I can share how to include new functions into micropython and OpenMV (it would be great if there is such tutorial)

Keep up good work!

Cheers

Again if you want to send a PR for that function, or just send the code here, I’ll add it.