The beach cleaning bot was a result of a 27 hour hackathon conducted in college for which we secured third place. A lot of problems exist because of excessive garbage and waste in our beaches. It is extremely harmful for various animals both on the shore and in the sea. Eventually since all this debris is washed into the sea, it pollutes that as well. This manages to affect us indirectly as this garbage is eaten by fish which are consumed by man.

Our beach cleaning bot is a primitive prototype to combat this menace and threat by automating the same. The project needs a ton of improvements, modifications and upgradations but this is the basic and general idea.

How our system works**Step1-Aerial picture of the beach using a drone or other Unmanned Aerial Vehicles.**

The first and foremost step would be to obtain an aerial view of the beach. This is important as it tells us where obstacles are, where the garbage is, where to start and where to end.

**Step 2-Image processing of the aerial view and extracting information.**

**Next** we perform image processing on the picture obtained to extract all the useful information from it. Now I will be honest- I have not worked with image processing before and this was my first time. So I simplified the image processing by a lot by making the aerial view myself using Microsoft Paint.

Here the yellow region represents sand and free region for the robot to move along. Red represents garbage. Blue is the start and green is the end. I know its not the perfect image or even realistic at that but its a start. Lets assume this is the aerial view of the beach taken by the drone.

Now the code below, written in python using OpenCV converts the image into a 8*8 2D array, where start is represented by 2, end is represented by 4, free movable space by 0, obstacles by 1 and garbage by 3.

`import cv2`

import numpy as np

img=cv2.imread('C:\\Users\\Me\\Desktop\\imagineer beach.jpg')

cv2.imshow('image',img)

d = img.shape

print (d)

z=0

arr= np.zeros([8, 8], dtype = int)

nitk=[]

for i in range(18,278,37):

for j in range(18,278,37):

nitk.append(img[i][j])

####print(img[i][j])

print(nitk)

k=0

for i in range(0,8):

for j in range(0,8):

b=nitk[k][0]

g=nitk[k][1]

r=nitk[k][2]

if(b>220 and (g>155 and g<170) and r<10):

arr[i][j]=2

#print("blue")

elif(b<10 and (g>230 and g<255) and r>230):

arr[i][j]=0

#print("yellow")

elif(b<10 and (g<10) and r<10):

arr[i][j]=1

#print("black")

elif((b>30 and b<50) and g<32 and r>230):

arr[i][j]=3

#print("red")

elif(b<80 and (g>170 and g<185) and r<40):

arr[i][j]=4

k=k+1

print(arr)

cv2.waitKey(0)

cv2.destroyAllWindows()

After this we obtain a 2D array like this.

Now its time to find the shortest path from start to end, without going over obstacles and ideally through garbage. For this we use the Grass fire algorithm

`s=[0,0]`

e=[7,7]

i=-1

h=0

x=s[0]

y=s[1]

print(arr)

if(x+1<8 and arr[x+1][y]!=1 and arr[x+1][y]==0):

arr[x+1][y]=i

if(y+1<8 and arr[x][y+1]!=1 and arr[x][y+1]==0):

arr[x][y+1]=i

if(x-1>-1 and arr[x-1][y]!=1 and arr[x-1][y]==0):

arr[x+1][y]=i

if(y-1>-1 and arr[x][y-1]!=1 and arr[x][y-1]==0):

arr[x][y-1]=i

print(arr)

while(arr[6][7]>=0 and arr[7][6]>=0):

b=np.where(arr==i)

j=len(b[0])

k=0

while(k<j):

x=b[0][k]

y=b[1][k]

if(x+1<8 and arr[x+1][y]!=1 and arr[x+1][y]==0):

arr[x+1][y]=i-1

if(y+1<8 and arr[x][y+1]!=1 and arr[x][y+1]==0):

arr[x][y+1]=i-1

if(x-1>-1 and arr[x-1][y]!=1 and arr[x-1][y]==0):

arr[x+1][y]=i-1

if(y-1>-1 and arr[x][y-1]!=1 and arr[x][y-1]==0):

arr[x][y-1]=i-1

k+=1

print(arr)

print(" ")

i-=1

Finally we must now extract the shortest path from start to end. I have not written the code to pass the garbage till now. Just from start to end(I will update the code with garbage route soon).

Now we need to extract coordinates of where the bot has to go to maneuver through the beach.

`m=0`

n=0

f=0

barr= np.zeros([18, 3], dtype = int)

mini=np.amin(arr)

result=np.where(arr == mini)

i=result[0][0]

j=result[0][1]

p=i

q=j

print(i,j)

barr[0][0]=mini

barr[0][1]=p

barr[0][2]=q

m=1

n=0

x=1

while((i!=1 and j!=0) or (i!=0 and j!=1)):

if(arr[i-1][j]==mini+x and i>0):

i-=1

barr[m][n]=mini+x

barr[m][n+1]=i

barr[m][n+2]=j

elif(arr[i][j-1]==mini+x and j>0):

j-=1

barr[m][n]=mini+x

barr[m][n+1]=i

barr[m][n+2]=j

elif(arr[i+1][j]==mini+x and i<6 ):

i+=1

barr[m][n]=mini+x

barr[m][n+1]=i

barr[m][n+2]=j

elif(arr[i][j+1]==mini+x and j<6):

j+=1

barr[m][n]=mini+x

barr[m][n+1]=i

barr[m][n+2]=j

m+=1

x+=1

f+=1

print(barr)

#print(arr)

#print(barr)

print(type(barr))

Next get them into a CSV file so that they can be fed to the bot.(I am still working on that)

FInally, a set of pictures-

## Comments