cutting grass

I am trying to make an automatic lawn mover
when I see objects that are not green I want to back away, when I see green grass I want to cut

The blob handling is very shaky, the frame size and position vary even when the mower is stationary.
Grass is not completely green but can contain other colors such as brown.
How can I recognize objects that are mainly green and where the light from the sun also varies.
I also want to find non green objects.

In thresholds 30, 100, -64, -8, -32, 32 is set but I don’t understand what it setting?
can you give me some tip
Regards Ulf Andersson

from pyb import UART
import time

UART 3, and baudrate.

uart = UART(3, 19200)

import sensor, image, time
threshold_index = 1 # green

Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)

The below thresholds track in general red/green/blue things. You may wish to tune them…

thresholds = [ (30, 100, 15, 127, 15, 127),
(30, 100, -64, -8, -32, 32),
(0, 15, 0, 40, -80, -20)]# generisk röd grön blå

MesurementNo = 0
MesurementX = 320
MesurementW = 0

sensor.set_windowing((0, 40, 320, 30))
sensor.set_auto_gain(False) #of for tracing
sensor.set_auto_whitebal(False) # of for tracing

img = sensor.snapshot()
for blob in img.find_blobs(thresholds, pixels_threshold=20, area_threshold=20, merge=True):
if blob.code() == 2: #green

Get largest rectangle and the left most

MesurementNo = MesurementNo + 1
if blob.x() < MesurementX:
MesurementX = blob.x()
if blob.w() > MesurementW:
MesurementW = blob.w()
if MesurementNo == 10:
#print(MesurementX, MesurementW , sep=’, ')
xx = “%d”%MesurementX + ", " + “%d”%MesurementW + “R”
MesurementNo = 0
MesurementX = 320
MesurementW = 0

Hi, I recommend you change approaches. Use the dataset editor of OpenMV IDE to collect a dataset of grass and not grass and train a CNN using Edge Impulse (see video details on our front page and product pages) to detect grass and not grass. It will work much better and is very little coding.

Were you able to proceed with this? As my RoboMower from 2007 is soon disintegrating, I’ve been contemplating making an automatic lawn mower myself.

Today i finished the rotor speed
controll so the first
Test is When it stop to rain

Den tors 6 maj 2021 15:14baljo via OpenMV Forums <> skrev:

1 Like