Gotowy podprojekt
This commit is contained in:
parent
93b16795b9
commit
4860028fa2
15
Marcin.py
15
Marcin.py
@ -9,6 +9,7 @@ class main():
|
|||||||
self.field = field
|
self.field = field
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.mode_value = 0
|
||||||
|
|
||||||
def get_output_layers(self,net):
|
def get_output_layers(self,net):
|
||||||
layer_names = net.getLayerNames()
|
layer_names = net.getLayerNames()
|
||||||
@ -27,7 +28,7 @@ class main():
|
|||||||
|
|
||||||
COLORS = np.random.uniform(0, 255, size=(len(classes), 3))
|
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)
|
blob = cv2.dnn.blobFromImage(image, scale, (416, 416), (0, 0, 0), True, crop=False)
|
||||||
|
|
||||||
@ -48,16 +49,18 @@ class main():
|
|||||||
confidence = scores[class_id]
|
confidence = scores[class_id]
|
||||||
if confidence > 0.5:
|
if confidence > 0.5:
|
||||||
class_ids.append(class_id)
|
class_ids.append(class_id)
|
||||||
print(class_id)
|
return class_ids[0]
|
||||||
print(scores)
|
|
||||||
return class_id
|
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
self.pole = self.ui.field_images[self.field.get_value(self.traktor.get_poz())]
|
self.pole = self.ui.field_images[self.field.get_value(self.traktor.get_poz())]
|
||||||
self.img = pygame.surfarray.array3d(self.pole)
|
self.img = pygame.surfarray.array3d(self.pole)
|
||||||
self.img = self.img.transpose([1,0,2])
|
self.img = self.img.transpose([1,0,2])
|
||||||
self.img = cv2.cvtColor(self.img, cv2.COLOR_RGB2BGR)
|
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):
|
def mode(self,mode):
|
||||||
self.mode_value = mode
|
self.mode_value = mode
|
||||||
@ -69,3 +72,5 @@ class main():
|
|||||||
return 2
|
return 2
|
||||||
elif self.mode_value in [8]:
|
elif self.mode_value in [8]:
|
||||||
return 3
|
return 3
|
||||||
|
elif self.mode_value in [6]:
|
||||||
|
return 10
|
||||||
|
9
ui.py
9
ui.py
@ -1,5 +1,5 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
import random
|
||||||
class game_ui():
|
class game_ui():
|
||||||
|
|
||||||
def __init__(self,traktor,field):
|
def __init__(self,traktor,field):
|
||||||
@ -34,8 +34,11 @@ class game_ui():
|
|||||||
self.pole1_surf_rect.y = self.POLE_POZ[1] - 75
|
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.traktor_img = ["traktor_d.png", "traktor_l.png", "traktor_u.png", "traktor_r.png"]
|
||||||
self.field_images = []
|
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_path = []
|
||||||
self.field_images.append(pygame.image.load('images/'+i))
|
# 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
|
# Zezwalamy na przechwytywanie klawiszy
|
||||||
pygame.event.pump()
|
pygame.event.pump()
|
||||||
|
Loading…
Reference in New Issue
Block a user