-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect_face_travelcode.py
54 lines (42 loc) · 1.13 KB
/
detect_face_travelcode.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
46
47
48
49
50
51
import socket
from time import sleep # 导入 socket 模块
import cv2
import numpy as np
def send_image(img, type):
'''
type:1表示发送行程卡 2
'''
img = cv2.resize(img, (640, 640))
client = socket.socket() # 创建 socket 对象
host = socket.gethostname() # 获取本地主机名
port = 11111 # 设置端口号
print('开始连接')
client.connect(('192.168.142.206', port))
print('开始传输')
if type == 1:
client.send(b'trac')
elif type == 2:
client.send(b'yolo')
send_bytes = b''
send_num = 0
send_bytes += img.data
while send_num < img.shape[0] * img.shape[1] * img.shape[2]:
send_num += client.send(send_bytes[send_num:])
print(send_num)
print('开始接受')
rec = client.recv(3)
client.close()
'''
这个地方使用-20表示红-30表示黄-40表示绿
返回的时候对应返回1,2,3
'''
if rec == b'-10':
return -1
if rec == b'-20':
return 0
if rec == b'-30':
return 1
if rec == b'-40':
return 2
else:
return float(rec) / 1000