Bonjour à tous,
je tente de faire un jeu ou le jouer doit retrouver les transformations qui ont été appliquées à une photo.
Il voit dont apparaître le photo puis la photo transformée. Il coche ensuite dans une fenêtre Tkinter pour indiquer les transformations qu'il pense avoir reconnues.
Puis relance pour obtenir de nouveau un traitement d'image et avoir son résultat à la question précédente (en même temps).
Le code ci-dessous. J'ai ajouté de print pour comprendre ce qui ne fonctionne pas et j'ai le message suivant :
[]
True
liste mémoire : [1, 3]
[1, 3]
False
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\EduPython\App\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "C:\Users\Cathestef\Dropbox\Perso\StefAtWork\habilitation-ISN\projetTrtImagesSRoebroeck\JeuTrtImagesSR_essai.py", line 27, in start
while game(compteur):
File "C:\Users\Cathestef\Dropbox\Perso\StefAtWork\habilitation-ISN\projetTrtImagesSRoebroeck\JeuTrtImagesSR_essai.py", line 68, in game
result(liste_traitements_joueur,memoire_traitements)
UnboundLocalError: local variable 'memoire_traitements' referenced before assignment

Donc j'ai fait affficher la liste memoire_traitements mais, bizarrment, il ne veut pas la prendre en paramètre ensuite : UnboundLocalError: local variable 'memoire_traitements' referenced before assignment
Pouvez-vous m'aider ?
Merci à vous.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#-*- coding: utf-8 -*-
from tkinter import*
from tkinter.filedialog import*
from PIL import Image
from random import*
from math import*
from fonctions_Tti import*
import os
import time
import numpy as np
 
def tirage(n,p):# parmi n transformations, on en choisit aléatoirement 4 (tirage sans remise)
    L1=[]
    for i in range(n):
        L1.append(i+1)
    L2=[]
    while len(L2)!=p:
        a=randint(1,len(L1))
        L2.append(L1[a-1])
        del(L1[a-1])
    return(L2)
 
def jeuTrtImages():
    transformations=['filigrane','decoupeBandes_H','decoupeBandes_V']#,'symetrieAxe_H','symetireAxe_V','rotation+90']
    compteur=0
    def start():
        while game(compteur):
            pass
 
    def game(compt):
        c=compt
        liste_2_traitements=tirage(len(transformations),2)
        #on va chercher les images dans le bon dossier
        liste_photos=os.listdir("../projetTrtImagesSRoebroeck/Photos_Tti")
        #on tire au hasard la photo à traiter
        PhotoATraiter=liste_photos[randint(0,len(liste_photos))-1]
        im1 = Image.open(PhotoATraiter)
        im1.show()   #on affiche la photo à traiter
        time.sleep(0.5)
        liste_traitements_ordi=np.zeros(6)
        for i in range(len(transformations)):
            liste_traitements_ordi[liste_2_traitements[i-1]]=1
        chaine_traitements_ordi=str()
        liste_traitements_ordi=str(liste_traitements_ordi)
        for i in range(6):
            chaine_traitements_ordi=chaine_traitements_ordi+liste_traitements_ordi[i]
        for traitement in liste_2_traitements:
            im1=eval(transformations[traitement-1])(im1)
        im1.show()
        time.sleep(0.5)
        im1.close()
        liste_traitements_joueur=[]
        if choix_filigrane.get()==1:
            liste_traitements_joueur.append(1)
        if choix_decoupeBandes_H.get()==1:
            liste_traitements_joueur.append(2)
        if choix_decoupeBandes_V.get()==1:
            liste_traitements_joueur.append(3)
        if choix_symHoriz.get()==1:
            liste_traitements_joueur.append(4)
        if choix_symVert.get()==1:
            liste_traitements_joueur.append(5)
        if choix_rotation.get()==1:
            liste_traitements_joueur.append(6)
        print(liste_traitements_joueur)
        print(liste_traitements_joueur==[])
        if liste_traitements_joueur!=[]:
            result(liste_traitements_joueur,memoire_traitements)
        liste_2_traitements.sort()
        memoire_traitements=liste_2_traitements
        print("liste mémoire : ",memoire_traitements)
 
    def result(joueur,ordi):
        juste=True
        new_score=0
        print("Traitements ordi : ",ordi)
        print("Traitements joueur : ",joueur)
        juste=(joueur==ordi)
        new_score=joueur_score.get()
        new_score+=juste
        joueur_score.set(new_score)
 
    tti_window=Toplevel()
    tti_window.title("Imageometrix")
 
    choix_filigrane= IntVar()
    choix_decoupeBandes_H= IntVar()
    choix_decoupeBandes_V= IntVar()
    choix_symHoriz= IntVar()
    choix_symVert= IntVar()
    choix_rotation= IntVar()
    joueur_score= IntVar()
    #memoire_traitements=StringVar()
    #liste_2_traitements=StringVar()
    liste_traitements_ordi= StringVar()
    liste_traitements_joueur= StringVar()
    liste_traitements_joueur_vieux= StringVar()
 
    tti_frame=Frame(tti_window, width=300)
    tti_frame.grid(column=0, row=0, sticky=(N,W,E,S))
    tti_frame.columnconfigure(0, weight=1)
    tti_frame.rowconfigure(0,weight=1)
 
    Label(tti_frame, text='Cliquer sur le bouton "Lancer",\n observer les deux images attentivement\n puis cocher les transformations qui permettent\nde passer de l\'une à l\'autre.').grid(column=1,row=1, sticky=W)
    Checkbutton(tti_frame, text='effet filigrane', variable=choix_filigrane).grid(column=1, row=3,sticky=W)
    Checkbutton(tti_frame, text='découpe en bandes horizontales',variable=choix_decoupeBandes_H).grid(column=1, row=4,sticky=W)
    Checkbutton(tti_frame, text='découpe en bandes verticales',variable=choix_decoupeBandes_V).grid(column=1, row=5,sticky=W)
    Checkbutton(tti_frame, text='symétrie axe horizontale',variable=choix_symHoriz).grid(column=1, row=6,sticky=W)
    Checkbutton(tti_frame, text='symétrie axe verticale', variable=choix_symVert).grid(column=1, row=7,sticky=W)
    Checkbutton(tti_frame, text='rotation antihoraire de 90°',variable=choix_rotation).grid(column=1, row=8,sticky=W)
 
    Button(tti_frame, text="Lancer", command=start).grid(column=2, row=2)
 
    Label(tti_frame, text="Score").grid(column=1, row=9,sticky=W)
    Label(tti_frame, textvariable=joueur_score).grid(column=1, row=10,sticky=W)
 
if __name__=='__main__':
    jeuTrtImages()