find_displacement()

General discussion about topics related to OpenMV.
mcenhillk
Posts: 2
Joined: Mon Sep 25, 2017 11:09 am

find_displacement()

Postby mcenhillk » Mon Sep 25, 2017 11:49 am

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.

Code: Select all

import sensor, image, time, pyb, utime

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.B64x64)
sensor.skip_frames(time = 2000)
clock = time.clock()

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

while(True):
    clock.tick()
    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).
dx-dy.png
dx-dy.png (22.33 KiB) Viewed 138 times

Am I missing something here? Am I using find_displacement() correctly?
User avatar
kwagyeman
Posts: 1246
Joined: Sun May 24, 2015 2:10 pm

Re: find_displacement()

Postby kwagyeman » Mon Sep 25, 2017 12:15 pm

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.
Nyamekye,
User avatar
kwagyeman
Posts: 1246
Joined: Sun May 24, 2015 2:10 pm

Re: find_displacement()

Postby kwagyeman » Mon Sep 25, 2017 12:17 pm

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.
Nyamekye,
mcenhillk
Posts: 2
Joined: Mon Sep 25, 2017 11:09 am

Re: find_displacement()

Postby mcenhillk » Mon Sep 25, 2017 3:54 pm

int(dy).png
int(dy).png (11.7 KiB) Viewed 132 times
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. :)

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! :D

Return to “General Topics”

Who is online

Users browsing this forum: Google [Bot] and 2 guests