-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalisationServer2D.py
More file actions
executable file
·58 lines (48 loc) · 2.04 KB
/
localisationServer2D.py
File metadata and controls
executable file
·58 lines (48 loc) · 2.04 KB
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
import cameraLocalisation2D
import socketserver
import cv2 as cv
class Handler(socketserver.BaseRequestHandler):
def setup(self):
self.fishEyeCamera = cameraLocalisation2D.FishEyeCamera(deviceID=1)
self.robotDetector = cameraLocalisation2D.RobotDetector(numberOfColours=3)
# robotDetector.calibrateColour(self.fishEyeCamera)
self.robotDetector.setCalibration([360.0, 140.5, 220.9], [15.7, 12.5, 8.6])
self.robotDetector.displayCalibration()
def handle(self):
# self.data = self.request.recv(1024).strip()
# print "{} wrote".format(self.client_address[0])
# print self.data
while True:
# TODO: It would be much better if the camera and detector system were
# not part of this handler
undistortedFrame = self.fishEyeCamera.getUndistortedFrame()
self.robotDetector.updateLocations(undistortedFrame, self.fishEyeCamera, debug=False)
cv.imshow("Processed Frame", undistortedFrame)
result = ""
for robot in self.robotDetector.robots:
result += "\n" + str(robot)
self.request.sendall(result)
key = cv.waitKey(16) # 60 frames/sec
if key != -1:
print(key)
if key == 1048689: # q
break
if __name__ == "__main__":
# fishEyeCamera = cameraLocalisation2D.FishEyeCamera(deviceID=0)
# robotDetector = cameraLocalisation2D.RobotDetector(numberOfColours=3)
# while True:
# undistortedFrame = fishEyeCamera.getUndistortedFrame()
# robotDetector.updateLocations(undistortedFrame, fishEyeCamera, debug=True)
# cv.imshow("Processed Frame", undistortedFrame)
# key = cv.waitKey(16) # 60 frames/sec
# if key != -1:
# print key
# if key == 1048689: # q
# break
# exit()
host = "localhost"
port = 9999
server = socketserver.TCPServer((host, port), Handler)
print("Starting Server")
server.serve_forever()
print("Server Finished")