-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetect_tester.py
112 lines (89 loc) · 3.2 KB
/
detect_tester.py
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
from Tkinter import *
from PIL import Image, ImageTk, ImageDraw
import os, time, thread, re, copy
import draw, math, detect, core, cv2
class LogLine():
pass
class Player():
def __init__(self, zeroX, zeroY, path='datalog'):
self.zeroX = zeroX
self.zeroY = zeroY+2
self.path = path
self.files = []
for f in os.listdir(path):
if f.endswith('jpg'):
self.files.append(f)
self.top=Tk()
self.top.geometry('670x600')
self.can = Canvas(self.top)
self.can.pack()
self.can.config(width=670, height=500)
for i in range(-450,450,50):
self.can.create_line(640, i+self.zeroY, 670, i+self.zeroY)
self.can.create_text((655, i+self.zeroY+9),text=str(abs(i)))
for i in range(-650,640,50):
self.can.create_line(i+self.zeroX, 480, i+self.zeroX, 500)
self.can.create_text((i+self.zeroX+15, 490),text=str(abs(i)))
self.label=Label(self.top,text='',font='Helvetica -12')
self.label.pack()
self.label2=Label(self.top,text='',font='Helvetica -12')
self.label2.pack()
self.scale=Scale(self.top,from_=0,to=len(self.files)-1,orient=HORIZONTAL,command=self.resize)
self.scale.set(0)
self.scale.pack(fill=X)
self.top.bind("<Right>", self.next)
self.top.bind("<Left>", self.prev)
self.top.bind("<Down>", self.next10)
self.top.bind("<Up>", self.prev10)
self.top.bind("<q>", lambda event: self.top.quit())
self.top.bind("<Motion>", self.mouseMove)
self.top.bind("<space>", self.to600)
self.last_img = None
mainloop()
def getImg(self,n):
image = Image.open(self.path+"/%s" % self.files[n])
frame = cv2.imread(self.path+"/%s" % self.files[n])
b = core.GROUND_X - detect.bird_h(frame, core.DETECT_BIRD_Y, core.GROUND_X, core.PIPE_SPACE)
draw = ImageDraw.Draw(image)
r = 4
draw.line((0,core.DETECT_BIRD_Y,640,core.DETECT_BIRD_Y),fill='#000',width=1)
draw.ellipse((b-r, core.DETECT_BIRD_Y-r, b+r, core.DETECT_BIRD_Y+r), fill='#0ff')
del draw
self.photo = ImageTk.PhotoImage(image)
return self.photo
def showImg(self,n):
print self.files[n]
img = self.can.create_image(0, 0, image=self.getImg(n), anchor=NW)
if self.last_img:
self.can.delete(self.last_img)
self.last_img = img
def resize(self, ev=None):
self.showImg(self.scale.get())
def next(self,e):
next_index = self.scale.get() + 1
if next_index < len(self.files):
self.scale.set(next_index)
def prev(self,e):
prev_index = self.scale.get() - 1
if prev_index >= 0:
self.scale.set(prev_index)
def next10(self,e):
next_index = self.scale.get() + 10
if next_index < len(self.files):
self.scale.set(next_index)
def prev10(self,e):
prev_index = self.scale.get() - 10
if prev_index >= 0:
self.scale.set(prev_index)
def to600(self,e):
if 700 <len(self.files):
self.scale.set(700)
def mouseMove(self, event):
self.mouse_x = event.x
self.mouse_y = event.y
self.label2.config(text="x: %f, y: %f"%(abs(event.x-self.zeroX), abs(event.y-self.zeroY)))
if __name__ == '__main__':
if len(sys.argv) == 2:
p = Player(600,323,sys.argv[1])
else:
p = Player(600,323)