Skip to content

Commit fe0ce3d

Browse files
author
Loïc Vanden Bemden
committed
Release v2.1 pushed
1 parent 6501d09 commit fe0ce3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1795
-1223
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
# Blob Simulation & Detection
22
Détection d'un blob dans une image ainsi que détection des comprimés de nourriture. Simulation d'un blob dans PyGame à travers un système multi-agents à connaissance partagée.
33

4+
## Release 2.1 - *7/06/2019*
5+
6+
### Modifications :
7+
+ Déplacement des scripts dans le dossier root
8+
+ Changement du nom des fichiers enregistrés par la détection
9+
+ Automatisation des différents scripts, ajout d'un fonctionnement en mode "caché".
10+
+ Automatisation de la simulation avec ajouts de paramètres et sauvegarde finale
11+
+ Ajout d'un paramètre pour initialiser de la nourriture dans la simulation
12+
+ Ajout d'un paramètre d'affichage dans la simulation
13+
+ Uniformisation des paramètres dans les différents scripts
14+
+ Possibilité de raffiner un modèle détecté avec un fichier d'informations supplémentaires
15+
+ Variables de couleur déplacées dans un fichier json séparé
16+
+ Ajout de fichiers d'exemples pour les différents scripts
17+
18+
### Scripts :
19+
+ Setup : `python setup.py -i data/example.jpg`
20+
+ Detection : `python detect.py -i data/example.jpg`
21+
+ Simulation : `python play.py -i data/output-examples/example-detect.board -s 3`
22+
+ Compare : `python compare.py --first data/output-examples/simulation/10_loops/10_loops.board --second data/output-examples/simulation/100_loops/100_loops.board -s 3`
23+
24+
Les différentes sorties produites sont les suivantes :
25+
![Sortie du script de détection](data/output-examples/example-detect-details.jpg?raw=true "Sortie du script de détection")
26+
![Sortie de la simulation après 100 itérations](data/output-examples/simulation/100_loops/100_loops.jpg?raw=true "Sortie de la simulation après 100 itérations")
27+
![Sortie du script de comparaison](data/compare_init_with_100.jpg?raw=true "Sortie du script de comparaison")
28+
29+
430
## Release 2.0 - *27/05/2019*
531

632
Le passage à cette release invalide les fichiers de sauvegarde précédents, le format ayant été modifié.
@@ -17,7 +43,6 @@ La nouvelle interface de la simulation produira des images comme celle-ci :
1743

1844
![Interface de simulation](example/test-run.jpg?raw=true "Interface de simulation")
1945

20-
2146
Pour exécuter le script de comparaison sur un exemple :
2247
`python compare.py --first example/test.board --second example/test-run.board`
2348

compare.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,44 @@
1717
import argparse
1818
from simulation import board
1919
import pygame
20-
from pygame.locals import QUIT
20+
from pygame.locals import QUIT, KEYDOWN, K_ESCAPE
2121

2222

2323
def main():
2424
ap = argparse.ArgumentParser()
2525
ap.add_argument("--first", required=True, help="first board file")
2626
ap.add_argument("--second", required=True, help="second board file")
27-
ap.add_argument("-s", "--scale", type=float, default=10, help="scale display (default: x10")
28-
ap.add_argument("-o", "--output", type=str, help="give a name to save the jpeg file")
27+
ap.add_argument("-s", "--scale", type=float, default=10,
28+
help="Scales board resolution by this factor (default: x10)")
29+
ap.add_argument("-o", "--output", type=str, help="Give a name to save the jpeg file")
2930
args = ap.parse_args()
3031

31-
board_1 = board.Board(0,0)
32+
board_1 = board.Board(0, 0)
3233
board_1.load(args.first)
3334

34-
board_2 = board.Board(0,0)
35+
board_2 = board.Board(0, 0)
3536
board_2.load(args.second)
3637

3738
board_comp = board_1.compare(board_2)
3839

3940
if board_comp is None:
4041
return
4142

42-
pygame.init()
43-
4443
width = int(board_1.width * args.scale)
4544
height = int(board_1.height * args.scale)
46-
window = pygame.display.set_mode((width, height))
4745

4846
game_surface = pygame.Surface((board_1.width, board_1.height))
4947
pixel_array = pygame.PixelArray(game_surface)
5048
for x in range(board_1.width):
5149
for y in range(board_1.height):
52-
pixel_array[x,y] = (0, 0, 0)
50+
pixel_array[x, y] = (0, 0, 0)
5351

5452
val = max(-255, min(board_comp.get_blob(x, y), 255))
5553
if val < 0:
56-
val = - val # int(-val/2) + 125
54+
val = - val # int(-val/2) + 125
5755
pixel_array[x, y] = (val/4, val/4, val)
5856
elif val > 0:
59-
val = val # int(val/2) + 125
57+
val = val # int(val/2) + 125
6058
pixel_array[x, y] = (val, val/4, val/4)
6159
else:
6260
if not board_comp.is_touched(x, y):
@@ -66,24 +64,27 @@ def main():
6664
pixel_array[x, y] = (125, 75, 75)
6765

6866
if board_comp.has_food(x, y):
69-
pixel_array[x, y] = (0, board_comp.foods[x, y], 0)
67+
pixel_array[x, y] = (0, board_comp.foods[x, y], 0)
7068

7169
del pixel_array
7270

7371
game_window = pygame.transform.scale(game_surface, (width, height))
7472

75-
window.blit(game_window, (0, 0))
76-
pygame.display.flip()
77-
78-
ended = False
79-
while not ended:
80-
pygame.time.wait(10)
81-
for event in pygame.event.get():
82-
if event.type == QUIT:
83-
ended = True
84-
8573
if args.output is not None:
86-
pygame.image.save(window, args.output)
74+
pygame.image.save(game_window, args.output)
75+
76+
else:
77+
pygame.init()
78+
window = pygame.display.set_mode((width, height))
79+
window.blit(game_window, (0, 0))
80+
pygame.display.flip()
81+
82+
ended = False
83+
while not ended:
84+
pygame.time.wait(10)
85+
for event in pygame.event.get():
86+
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
87+
ended = True
8788

8889

8990
if __name__ == "__main__":

data/_MG_0001.JPG

4.95 MB
Loading

data/_MG_0132.JPG

9.45 MB
Loading

data/_MG_0133.JPG

9.44 MB
Loading

data/_MG_0207.JPG

5.18 MB
Loading

data/compare_init_with_100.jpg

25.5 KB
Loading

data/example.jpg

5.18 MB
Loading
251 KB
Loading

data/output-examples/example-detect.board

Lines changed: 161 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)