cutting grass

Discussion related to "under the hood" OpenMV topics.
Ulf Andersson
Posts: 7
Joined: Sun Sep 22, 2019 10:48 am

cutting grass

Postby Ulf Andersson » Thu Aug 13, 2020 3:09 pm

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

Re: cutting grass

Postby kwagyeman » Thu Aug 13, 2020 4:25 pm

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.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests