Gotowy podprojekt

This commit is contained in:
Marcin Kwapisz 2020-05-18 22:05:58 +02:00
parent 93b16795b9
commit 4860028fa2
2 changed files with 16 additions and 8 deletions

View File

@ -9,6 +9,7 @@ class main():
self.field = field
self.ui = ui
self.path = path
self.mode_value = 0
def get_output_layers(self,net):
layer_names = net.getLayerNames()
@ -27,7 +28,7 @@ class main():
COLORS = np.random.uniform(0, 255, size=(len(classes), 3))
net = cv2.dnn.readNet("si_final.weights", "si.cfg")
net = cv2.dnn.readNet("si_20000.weights", "si.cfg")
blob = cv2.dnn.blobFromImage(image, scale, (416, 416), (0, 0, 0), True, crop=False)
@ -48,16 +49,18 @@ class main():
confidence = scores[class_id]
if confidence > 0.5:
class_ids.append(class_id)
print(class_id)
print(scores)
return class_id
return class_ids[0]
def main(self):
self.pole = self.ui.field_images[self.field.get_value(self.traktor.get_poz())]
self.img = pygame.surfarray.array3d(self.pole)
self.img = self.img.transpose([1,0,2])
self.img = cv2.cvtColor(self.img, cv2.COLOR_RGB2BGR)
self.traktor.set_mode(self.mode(self.recognition(self.img)))
self.reco = self.mode(self.recognition(self.img))
if self.reco == 10:
print("Nic nie trzeba robić")
else:
self.traktor.set_mode(self.reco)
def mode(self,mode):
self.mode_value = mode
@ -69,3 +72,5 @@ class main():
return 2
elif self.mode_value in [8]:
return 3
elif self.mode_value in [6]:
return 10

9
ui.py
View File

@ -1,5 +1,5 @@
import pygame
import random
class game_ui():
def __init__(self,traktor,field):
@ -34,8 +34,11 @@ class game_ui():
self.pole1_surf_rect.y = self.POLE_POZ[1] - 75
self.traktor_img = ["traktor_d.png", "traktor_l.png", "traktor_u.png", "traktor_r.png"]
self.field_images = []
for i in ['gleba_pix.png','gleba_chwasty_pix.png','sadzonka_suchi_pix.png','sadzonka_chwasty_pix.png','gleba_mokra_pix.png','gleba_mokra_chwasty.png','sadzonka_mokra_pix.png','sadzonka_mokra_chwasty_pix.png','gotowy_burak_pix.png']:
self.field_images.append(pygame.image.load('images/'+i))
# self.field_images_path = []
# self.random = random.randint(0,99)
for i in ['gleba_pix','gleba_chwasty_pix','sadzonka_suchi_pix','sadzonka_chwasty_pix','gleba_mokra_pix','gleba_mokra_chwasty','sadzonka_mokra_pix','sadzonka_mokra_chwasty_pix','gotowy_burak_pix']:
# self.field_images_path.append("images/"+i+"/"+i+str(self.random)+".png")
self.field_images.append(pygame.image.load("images/"+i+".png"))
# Zezwalamy na przechwytywanie klawiszy
pygame.event.pump()