45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
#sudo ~/build/opencv-webcam-demo/opencv-webcam-demo --data ~/affdex-sdk/data --faceMode 1 --numFaces 40 --draw 1
|
|
|
|
import subprocess
|
|
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
|
|
|
|
proc = subprocess.Popen([
|
|
'/home/crowd/build/opencv-webcam-demo/opencv-webcam-demo',
|
|
"--data", "/home/crowd/affdex-sdk/data",
|
|
"--faceMode", "1",
|
|
"--numFaces", "40",
|
|
"--draw", "1",
|
|
"--pfps", "5",
|
|
"--cfps", "5",
|
|
],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
clients = []
|
|
class EchoOutput(WebSocket):
|
|
|
|
# def handleMessage(self):
|
|
# # echo message back to client
|
|
# self.sendMessage(self.data)
|
|
|
|
def handleConnected(self):
|
|
clients.append(self)
|
|
print(self.address, 'connected')
|
|
|
|
def handleClose(self):
|
|
clients.remove(self)
|
|
print(self.address, 'closed')
|
|
|
|
server = SimpleWebSocketServer('', 8080, EchoOutput)
|
|
|
|
def send_message(msg):
|
|
print "send", msg, "to", len(clients), "clients"
|
|
for client in list(clients):
|
|
client.sendMessage(u''+msg)
|
|
|
|
while proc.poll() is None:
|
|
server.serveonce()
|
|
line = proc.stdout.readline()
|
|
if line == '':
|
|
continue
|
|
send_message(line)
|
|
#print "test:", line.rstrip()
|
|
|