-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
45 lines (35 loc) · 1.11 KB
/
server.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
import zmq
import cv2
import base64
class Server:
class __Server:
def __init__(self):
pass
instance = None
def __init__(self):
if not Server.instance:
Server.instance = Server.__Server()
else:
print "class already exists"
# initiate server functions
context = zmq.Context()
socket = context.socket(zmq.PAIR)
# Convert to base64 image for easy transferring
def convertToBase64(self, img):
cnt = cv2.imencode('.png', img)[1]
return base64.encodestring(cnt)
# open connection to c# server
def openConnection(self):
connectionString = "127.0.0.1:9023"
self.socket.bind("tcp://" + connectionString)
print "Connected to server on %s" % connectionString
# Close server connection
def closeConnection(self):
self.socket.close()
print "Connection closed"
# Send image of kenteken to c# server
def sendJsonData(self, json):
# debug image
# img = cv2.imread('img/kenteken-apart.png')
self.socket.send_string(json)
print "Image sent"