-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskt_test.py
More file actions
60 lines (50 loc) · 1.49 KB
/
skt_test.py
File metadata and controls
60 lines (50 loc) · 1.49 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
59
60
import time
import socket
import json
import cv2
import sys
import base64
pub_face_data = {"cmd":"P13","subcmd":"req",
"content":
{
"eigen_value":"xxxxxxxxxxxxx",#base64
"eigen_name":"",#""
"area_id":"" #random NO depu
}
}
ip = '33.22.11.00'
port = 12301
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sk.connect((ip, port))
except:
print("fail to connect socket server")
sys.exit(1)
print("ckt connect success")
while True:
frame = cv2.imread('face.jpg')
cv2.imshow('show', frame)
cv2.waitKey(0)
retval, buffer = cv2.imencode('.jpeg', frame)
base64_data = base64.b64encode(buffer)
base64_string = base64_data.decode()
pub_face_data['content']['eigen_value'] = str(base64_string)
pub_face_data['content']['area_id'] = '201123275'
try:
data_dumped = json.dumps(pub_face_data)
send_data = 'PCLIENT ' + data_dumped +'\r\n'
# encode('utf-8')
# encode('utf-8')
# encode('utf-8')
err_code = sk.sendall(send_data.encode('utf-8'))
print(err_code)
except socket.error:
print('socket error,do reconnect')
# make connet as function and recall
time.sleep(3)
#break
except Exception as expmsg:
print('other error occur:{expmsg}')
break
print("send face data")
time.sleep(10)