-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·75 lines (57 loc) · 2.4 KB
/
main.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
#!/usr/bin/env python2
import sys
import cv2
from processor import Processor
from processor import FPS
from processor import VideoHandler
from threadedtcpserver import ConnectionThread
if __name__ == '__main__':
# -- Flags --
# Second argument is always debug, third graphical if applicable
if len(sys.argv) == 3:
if sys.argv[1] == "True":
debug = True
else:
debug = False
if sys.argv[2] == "True":
graphical = True
else:
graphical = False
else:
debug = True
graphical = True
if graphical:
goalwinname = "NetCam"
pyramidwinname = "UsbCam"
cv2.namedWindow(goalwinname)
cv2.namedWindow(pyramidwinname)
processor = Processor()
frisbeecamera = VideoHandler("http://10.29.45.11/mjpg/video.mjpg")
climbingcamera = VideoHandler(0)
fps = FPS()
connThread = ConnectionThread() # The tcp server is threaded
# becasue waiting for a connection is blocking
# Trackbars to find best hsv min/max values
if debug and graphical:
cv2.createTrackbar("H-Min", goalwinname, processor.t_huemin, 255, processor.huemin )
cv2.createTrackbar("S-Min", goalwinname, processor.t_saturationmin, 255, processor.saturationmin )
cv2.createTrackbar("V-Min", goalwinname, processor.t_valuemin, 255, processor.valuemin )
cv2.createTrackbar("H-Max", goalwinname, processor.t_huemax, 255, processor.huemax )
cv2.createTrackbar("S-Max", goalwinname, processor.t_saturationmax, 255, processor.saturationmax )
cv2.createTrackbar("V-Max", goalwinname, processor.t_valuemax, 255, processor.valuemax )
connThread.start()
while True:
if frisbeecamera.captureenabled:
goalimg = frisbeecamera.get_img()
processedgoalimg, goalnum = processor.find_squares(goalimg, debug, graphical)
if graphical:
cv2.imshow(goalwinname, processedgoalimg)
if climbingcamera.captureenabled:
pyramidimg = climbingcamera.get_img()
processedpyramidimg, pyramidnum = processor.find_squares(pyramidimg, debug, graphical)
if graphical:
cv2.imshow(pyramidwinname, processedpyramidimg)
# The processor thread sets the distance; connThread reads
connThread.distance = processor.distance
print fps.determineFPS()
cv2.waitKey(30)