I picked up an M7 to make a proof-of-concept of a tire slip angle sensor. The camera needs to be able to detect a dx/dy of the road surface moving beneath the car. The code right now is REALLY simple as I am still learing uPython, this camera, and ARM.

import sensor, image, time, pyb, utime

sensor.skip_frames(time = 2000)
clock = time.clock()

oldImage = sensor.snapshot().mean_pooled(4, 4)

    newImage = sensor.snapshot().mean_pooled(4, 4)
    x,y,c = newImage.find_displacement(oldImage)
    oldImage = newImage

    print("dx: %10f dy: %10f confidence: %10f FPS: %f time: %d" % (x, y, c, clock.fps(), utime.ticks_ms()))

Like I said, real simple.

The camera is about 4" off of the desk and is moved back and forth about 18" over a 5 second period. The desk that I’m testing on is unfinished plywood so there is definition in the surface. I ploted the data in Excel to see the measured displacement and it looks like statistical noise (I’ve attached the graphs).

Am I missing something here? Am I using find_displacement() correctly?

The output is really noisy by default. If you want to Clean the noise up use int() on the floating point outputs to convert them to decimal and it will work like you think.

I was trying to output the data like an accelerometer but that’s probably too advanced for folks.

The reason it’s so noisy is because someone wanted sub pixel accuracy. So it’s trying to interpolate a position between pixels. This is highly affected by noise.

Ok, that’s a little better. The orange dots are the ‘dy’ output, and the green/red dots are confidence level (red if <= 0.2).

The good news, I had to slow down the loop. Hopefully this means the camera will work going 80 mph 4" above concrete. :slight_smile:

The bad news, I might have to pull out my stats book to figure out how to clean the data. :cry:

Thanks for the help and the OpenMV project!

:edit: Instead of the stats book I should probably be looking at a kalman filter, especially since you wanted this to behave like an accelerameter. W00t! I’ve been looking for an excuse to learn those! :smiley:

Sounds really cool, did you make any progress on this?