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.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((0, 40, 320, 30))
sensor.skip_frames(20)
sensor.set_auto_gain(False) #of for tracing
sensor.set_auto_whitebal(False) # of for tracing


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

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”
uart.write(xx)
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 <openmv1@discoursemail.com> skrev:

1 Like