-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvrcam.py
More file actions
49 lines (38 loc) · 1.06 KB
/
vrcam.py
File metadata and controls
49 lines (38 loc) · 1.06 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
#/usr/bin/env python
import threading
import serial
import cv2
import SocketServer
from videoThread import videoThread
__author__ = "Matt Anderson"
#Open serial communication with arduino
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1);
HOST, PORT = "localhost", 9999
class UDPHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
socket = self.request[1]
#print data
ser.write(data)
def init():
#OpenCV setup
cam = cv2.VideoCapture(0)
camThread = videoThread(cam)
camThread.daemon = True
camThread.start()
sockSer = SocketServer.UDPServer((HOST, PORT), UDPHandler)
sockThread = threading.Thread(target=sockSer.serve_forever)
sockThread.daemon = True
sockThread.start()
def exit():
ser.close()
camThread.stop()
sockThread.stop()
if __name__ == "__main__":
init()
command = ''
while command != 'exit':
command = raw_input('command: ')
#if command != 'exit':
#ser.write(command)
exit()