2024-03-23 13:46:48 +01:00
|
|
|
import pygame
|
|
|
|
import displayControler as dCon
|
|
|
|
import random
|
2024-05-25 02:00:19 +02:00
|
|
|
import neuralnetwork
|
|
|
|
import os
|
2024-03-23 13:46:48 +01:00
|
|
|
|
|
|
|
class Image:
|
|
|
|
def __init__(self):
|
|
|
|
self.plants_image_dict={}
|
|
|
|
self.tractor_image=None
|
2024-04-15 10:02:09 +02:00
|
|
|
self.garage_image=None
|
2024-04-24 22:16:34 +02:00
|
|
|
self.stone_image=None
|
2024-04-27 00:59:48 +02:00
|
|
|
self.gasStation_image=None
|
2024-03-23 13:46:48 +01:00
|
|
|
def load_images(self):
|
2024-04-27 00:59:48 +02:00
|
|
|
files_plants={
|
|
|
|
0:"borowka",
|
2024-03-23 13:46:48 +01:00
|
|
|
1:"kukurydza",
|
|
|
|
2:"pszenica",
|
|
|
|
3:"slonecznik",
|
|
|
|
4:"winogrono",
|
2024-04-24 22:16:34 +02:00
|
|
|
5:"ziemniak",
|
|
|
|
6:"dirt",
|
2024-04-28 12:58:58 +02:00
|
|
|
7:"mud",
|
|
|
|
8:"road"}
|
2024-03-23 13:46:48 +01:00
|
|
|
for index in files_plants:
|
2024-04-24 22:16:34 +02:00
|
|
|
if index >= 6:
|
|
|
|
plant_image = pygame.image.load("images/" + files_plants[index] + ".jpg")
|
|
|
|
else:
|
|
|
|
plant_image=pygame.image.load("images/plants/"+files_plants[index]+".jpg")
|
2024-03-23 13:46:48 +01:00
|
|
|
plant_image=pygame.transform.scale(plant_image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
|
|
|
self.plants_image_dict[files_plants[index]]=plant_image
|
|
|
|
tractor_image=pygame.image.load("images/traktor.png")
|
|
|
|
tractor_image=pygame.transform.scale(tractor_image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
2024-04-15 10:02:09 +02:00
|
|
|
garage=pygame.image.load("images/garage.png")
|
|
|
|
self.garage_image=pygame.transform.scale(garage,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
2024-04-24 22:16:34 +02:00
|
|
|
stone=pygame.image.load("images/stone.png")
|
|
|
|
self.stone_image=pygame.transform.scale(stone,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
2024-04-27 00:59:48 +02:00
|
|
|
gasStation=pygame.image.load("images/gasStation.png")
|
|
|
|
self.gasStation_image=pygame.transform.scale(gasStation,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
2024-04-24 22:16:34 +02:00
|
|
|
|
2024-03-23 13:46:48 +01:00
|
|
|
def return_random_plant(self):
|
2024-05-11 14:18:40 +02:00
|
|
|
x=random.randint(0,5) #disabled dirt and mud generation
|
2024-03-23 13:46:48 +01:00
|
|
|
keys=list(self.plants_image_dict.keys())
|
|
|
|
plant=keys[x]
|
2024-03-24 23:30:02 +01:00
|
|
|
return (plant,self.plants_image_dict[plant])
|
2024-03-23 13:59:24 +01:00
|
|
|
|
|
|
|
def return_plant(self,plant_name):
|
2024-04-15 10:02:09 +02:00
|
|
|
return (plant_name,self.plants_image_dict[plant_name])
|
|
|
|
|
|
|
|
def return_garage(self):
|
2024-04-24 22:16:34 +02:00
|
|
|
return self.garage_image
|
|
|
|
|
|
|
|
def return_stone(self):
|
|
|
|
return self.stone_image
|
2024-04-27 00:59:48 +02:00
|
|
|
|
|
|
|
def return_gasStation(self):
|
|
|
|
return self.gasStation_image
|
2024-05-26 01:37:01 +02:00
|
|
|
|
|
|
|
# losowanie zdjęcia z testowego datasetu bez powtórzeń
|
|
|
|
imagePathList = []
|
2024-05-25 02:00:19 +02:00
|
|
|
def getRandomImageFromDataBase():
|
|
|
|
label = random.choice(neuralnetwork.labels)
|
|
|
|
folderPath = f"dataset/test/{label}"
|
|
|
|
files = os.listdir(folderPath)
|
|
|
|
random_image = random.choice(files)
|
|
|
|
imgPath = os.path.join(folderPath, random_image)
|
|
|
|
|
2024-05-26 01:37:01 +02:00
|
|
|
while imgPath in imagePathList:
|
2024-05-26 13:58:48 +02:00
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
quit()
|
2024-05-26 01:37:01 +02:00
|
|
|
label = random.choice(neuralnetwork.labels)
|
|
|
|
folderPath = f"dataset/test/{label}"
|
|
|
|
files = os.listdir(folderPath)
|
|
|
|
random_image = random.choice(files)
|
|
|
|
imgPath = os.path.join(folderPath, random_image)
|
|
|
|
|
|
|
|
imagePathList.append(imgPath)
|
|
|
|
|
2024-05-26 01:08:47 +02:00
|
|
|
image = pygame.image.load(imgPath)
|
|
|
|
image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
|
|
|
return image, label, imgPath
|
2024-06-07 00:02:36 +02:00
|
|
|
|
|
|
|
def getSpedifiedImageFromDatabase(label):
|
|
|
|
folderPath = f"dataset/test/{label}"
|
|
|
|
files = os.listdir(folderPath)
|
|
|
|
random_image = random.choice(files)
|
|
|
|
imgPath = os.path.join(folderPath, random_image)
|
|
|
|
|
|
|
|
while imgPath in imagePathList:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
quit()
|
|
|
|
label = random.choice(neuralnetwork.labels)
|
|
|
|
folderPath = f"dataset/test/{label}"
|
|
|
|
files = os.listdir(folderPath)
|
|
|
|
random_image = random.choice(files)
|
|
|
|
imgPath = os.path.join(folderPath, random_image)
|
|
|
|
|
|
|
|
imagePathList.append(imgPath)
|
|
|
|
|
|
|
|
image = pygame.image.load(imgPath)
|
|
|
|
image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
|
|
|
return image, label, imgPath
|