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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
| #!/usr/bin/python3.5
# -*-coding:utf-8 -*
from tkinter import *
from PIL import Image, ImageTk
from turtle import *
from couleurs import COULEURS
from random import choice
import time
import os
import numpy as np
import cv2
from Homographie import *
from vidéo_chat_GUI import *
principale=Tk()
principale.title('Cockpit')
principale.option_readfile('apparence', priority=None)
#Création des cadres du cockpit
f1=LabelFrame(principale, name='f1', width=50, height = 50, padx=10, pady=10, text='f1', relief = 'flat', labelanchor='nw')
f1.grid(column=0, row=0,columnspan=6)
f2=LabelFrame(principale, name='f2', width=50, height = 50, padx=1, pady=1, text='f2', relief = 'flat', labelanchor='nw')
f2.grid(column=0, row=1,columnspan=3)
f3=LabelFrame(principale, name='f3', width=50, height = 50, padx=1, pady=1, text='f3', relief = 'flat', labelanchor='nw')
f3.grid(column=0, row=2,columnspan=3)
f4=LabelFrame(principale, name='f4', width=50, height = 50, padx=1, pady=1, text='f4', relief = 'flat', labelanchor='nw')
f4.grid(column=4, row=1, rowspan =20)
f5=LabelFrame(principale, name='f5', width=50, height = 50, padx=1, pady=1, text='f5', relief = 'flat', labelanchor='nw')
f5.grid(column=4, row=2)
f6=LabelFrame(principale, name='f6', width=50, height = 50, padx=1, pady=1, text='f6', relief = 'flat', labelanchor='nw')
f6.grid(column=5, row=1, rowspan = 9)
#Définition des variables à afficher dans les widgets
posX=DoubleVar()
posY=DoubleVar()
typeOBJ = StringVar()
FIAB=DoubleVar()
DistCIBL=DoubleVar()
varCAM = IntVar()
CalibrageTuple = StringVar()
HOMO=np.zeros((3,3))
#---------FRAME1-------------
#---------FRAME2-------------
#Champ chargement mire
def UploadAction(event=None):
filename = filedialog.askopenfilename()
print('Selected:', filename)
uploaFILE = Button(f2, text='Chargement mire', command=UploadAction)
uploaFILE.grid(column=0,row=1)
#Champ tuple distance
def enregistrementCalibrageTuple(event):
''' Conversion text en tuple'''
# Fonction/opération de conversion à faire sur CalibrageTuple
CTuple = CalibrageTuple.get()
affichCAL.configure(text = 'Valeur de calibrage : {}'.format(CTuple))
return (0,0,0,0)
#Variable de contrôle
CalibrageTuple.set("Saisir 4 valeurs de calibrages")
#Champ
entreeCAL = Entry(f2, textvariable=CalibrageTuple, width=30)
entreeCAL.grid(column=0,row=2)
#Enregistrement de la saisie
entreeCAL.bind("<Return>", enregistrementCalibrageTuple)
#Affichage de la saisie
affichCAL = Label(f2, text=CalibrageTuple)
affichCAL.grid(column=0,row=3)
#Bouton calcul calibrage
def calibrage():
HOMOcal = Homo()
HOMOtxt = np.around(HOMOcal, decimals=2)
labMAT.configure(text = HOMOtxt)
global HOMO
HOMO = HOMOcal
return
b_cal = Button(f2, name='demarre', command = calibrage, text='Reconnaissance de distance :')
b_cal.grid(column=0,row=4, rowspan = 3)
#Affichage calcul homographie ok
labTxMAT = Label(f2, text="Matrice de changement de base :")
labTxMAT.grid(column=0,row=7)
HOMOcmd=np.zeros((3,3))
labMAT = Label(f2, text=HOMOcmd)
labMAT.grid(column=0,row=8)
#Affichage Matrice
#Affichage position X,Y
textXY = "Coord. X : {} / Coord. Y : {}".format(posX.get(), posY.get())
labXY = Label(f2, text=textXY)
labXY.grid(column=0,row=9)
#---------FRAME3-------------
#Texte choix objet (chat...)
labMENU = Label(f3, text='Choix de l\'objet à suivre :')
labMENU.grid(column=0,row = 0, columnspan = 2)
#Bouton choix classe d'objet
typeOBJ.set(CLASSES[8])
MenuOBJ = OptionMenu(f3, typeOBJ, *CLASSES)
MenuOBJ.grid(column=0,row = 1, columnspan = 2)
#Texte choix source (USB ou incoporée)
labCHCAM = Label(f3, text='Choix de la source de la vidéo :')
labCHCAM.grid(column=0,row = 2, columnspan = 2)
#Boutons choix source (USB ou incoporée)
vals = [0, 1, 2]
etiqs = ['Interne', 'USB', 'IP']
varCAM.set(vals[0])
for i in range(3):
BoutonCAM = Radiobutton(f3, variable=varCAM, text=etiqs[i], value=vals[i])
BoutonCAM.grid(column=i,row=3)
#Bouton lancement programme
def start():
global varCAM
CAP = captVID(varCAM.get())
update_vid(CAP)
b_start = Button(f3, name='demarre', command = start, text='Lancement programme')
b_start.grid(column=1,row=4)
#Insertion GIF anim f3
can2 = Canvas(f3, name='can3', width=260, height=260, bg='white')
can2.grid(column=0,row=5, columnspan=3)
photo2 = PhotoImage(file="A.gif")
can2.create_image(130,130, anchor = 'center', image=photo2, tag='photo')
ind2 = -1
def update2(delay=100):
global ind2
ind2 += 1
if ind2 == 51: ind2 = 0
photo2.configure(format="gif -index " + str(ind2))
f3.after(delay, update2)
update2()
#Bouton arrêt programme
def stop():
'''Bouton STOP, renvoie une valeur pour sortir d'une boucle'''
cv2.destroyAllWindows()
principale.destroy()
b_quit = Button(f3, name='stop', command = stop, text='Stop')
b_quit.grid(column=1,row=6)
#---------FRAME4-------------
#Zone de dessin pour affichage frame
zone_video = Canvas(f4, name='can7', width=800, height=800)
zone_video.grid(column=0,row=0)
def update_vid(CAP):
# get_frame depuis vidéo_chat_GUI.py
global HOMO
global zone_video
#Délai de rafraichissement
delay = 200
image_TRAITEE = get_frame(CAP, HOMO)
image_inter = Image.fromarray(image_TRAITEE)
photo = ImageTk.PhotoImage(image = image_inter)
zone_video.create_image(0, 0, image = photo, anchor = 'center')
f4.after(delay, update_vid, CAP)
#---------FRAME5-------------
#Zone de dessin pour repère
zone_dessin = Canvas(f5, name='can5', width=200, height=200)
zone_dessin.grid(column=0,row=0)
#fonction de dessin de grille
def dessiner(zone_dessin,X,Y):
#Nettoyage de la zone de dessin : supression du canvas et création d'un nouveau
zone_dessin.pack_forget()
zone_dessin = Canvas(f5, width=200, height=200)
zone_dessin.grid(column=0,row=0)
OFF = 0
#Module Turtle
t=RawPen(zone_dessin)
#Début du dessin Turtle
x = 0
L = 50
H = 50
t.up()
t.goto(-L, H)
t.pensize(4)
t.pencolor(choice(COULEURS))
while x < 2*10 and OFF!=1:
t.down()
t.goto(-L, H)
t.up()
x += 15
L = -L
if L >0 : H = -200+x
else :
H = 200-x
#Dessin
dessiner(zone_dessin,0,0)
#---------FRAME6-------------
#Insertion GIF anim f6
can = Canvas(f6, name='can6', width=260, height=260, bg='white')
can.grid(column=0,row=0)
photo = PhotoImage(file="B.gif")
can.create_image(130,130, anchor = 'center', image=photo, tag='photo')
ind = -1
def update(delay=10):
global ind
ind += 1
if ind == 51: ind = 0
photo.configure(format="gif -index " + str(ind))
f6.after(delay, update)
update()
#Affichage position X,Y
textXY = "Coord. X : {} / Coord. Y : {}".format(posX.get(), posY.get())
labXY = Label(f6, text=textXY)
labXY.grid(column=0,row=1)
#Affichage*: Objet trouvé, Confidence, Distance, Date-heure
textOBJ = "Objet trouvé : {}".format(typeOBJ.get())
labOBJ = Label(f6, text=textOBJ)
labOBJ.grid(column=0,row=2)
#Affichage*: Confidence
textFIAB = "Fiabilité de la recherche : {}".format(FIAB.get())
labFIAB = Label(f6, text=textFIAB)
labFIAB.grid(column=0,row=3)
#Affichage*: Distance
textCIBL = "Distance de cible : {}".format(DistCIBL.get())
labCIBL = Label(f6, text=textCIBL)
labCIBL.grid(column=0,row=4)
#Affichage*: Date-heure
textDET = "Heure détection : {}".format(time.strftime("%H:%M:%S"))
labDET = Label(f6, text=textDET)
labDET.grid(column=0,row=5)
#Affichage dessin fixe Dessin fixe
#Affichage vidéo bounding box
'''
tkinter.Label(f1, text='je suis dans F1 --- c\'est large').grid(row=0, column=0)
tkinter.Label(f2, text='je suis dans F2').grid(row=0, column=0)
tkinter.Label(f3, text='je suis dans F3').grid(row=0, column=0)
tkinter.Label(f4, text='je suis dans F4').grid(row=0, column=0)
tkinter.Label(f5, text='je suis dans F5').grid(row=0, column=0)
tkinter.Label(f6, text='je suis dans F6').grid(row=1, column=0)
'''
principale.mainloop() |
Partager