Optical Flow integration with MATLAB/Simulink

Hello everyone, I’m working on my graduation project of implementing a drone flight controller software on MATLAB/Simulink on Arduino Due. And as of now, I’m working on the stabilization part where I plan to use an optical flow sensor, and after doing some research I came up to the OpenMV H7 and I want to know how to implement an optical flow algorithm on it to use it with Lidar to be able to get flow_x and flow_y readings. Anyone experienced with something like this before?

Hi, see Examples → Camera → Optical Flow in the IDE. We can run phase correlation onboard to do this. However, it’s not exactly the best algorithm, but, it kinda works.

Hello, @kwagyeman

It seems like I have to connect the camera to see the examples, can you help on how to get the example script? I didn’t receive the camera yet.

Just turn off the Tools→Filter Examples by camera option in the IDE.

Thanks for replying, @kwagyeman .
Any advice on how to use these scripts properly to get flow measurements? I’m new to using optical flow scripts and planning to understand them to be able to integrate with altitude coming from external Lidar to be fed to the feedback loop on my controller.

Sorry, I’m not sure exactly what you are asking for here. If you look at the example and read the docs about the function being used find_displacement() it’s prety clear what our system can do.

As for transmitting the values, we are a microcontroller with a UART, you can easily transmit the data to any other MCU.

For communication with Arduino due you have various hardware interface options. See RPC examples. With DUE you can use SPI or UART and there are pros and cons that are project specific. Here we can point you in the right direction but requires work to adapt to your project. Try ChatGPT/ Grok . It can probably set you up with 80% of what you need if you constrain the problem enough.

The communication is not the matter here since the MAVLINK is supported through UAV toolbox in MATLAB and also SPI or I2C. But the question was, there is a lot of scripts in the Examples > Camera > OpticalFlow: absoulutetranslation.py, differentialrotation.py, … I was asking for any advice of what exact script to use to output ready flow_x, flow_y data to my flight controller to be integrated further with my altitude readings to output flow velocities in X, Y for my feedback to control the drone’s stabilization. @kwagyeman @Joe100A

Also, if anyone knows, the approximate frequency this operation can run at properly on its on-board chip?

Depends on the resolution and board variant. Please try out the example.

I will be using the Cam H7 Plus, but as mentioned above, I didn’t receive the camera yet, so I was asking for an approximate number as of any previous experience.

The default differential translation script runs at 112 fps at 64x64 pixels.

1 Like