5.24
This commit is contained in:
13
lane_server/client_test.py
Normal file
13
lane_server/client_test.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import zmq
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.REQ)
|
||||
socket.connect("tcp://localhost:6666")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('zmq client start....')
|
||||
while True:
|
||||
# str1 = input(":")
|
||||
socket.send_string('')
|
||||
message = socket.recv_pyobj()
|
||||
print(message)
|
||||
@@ -4,7 +4,7 @@ from loguru import logger
|
||||
import zmq
|
||||
from infer import Lane_model_infer
|
||||
import numpy as np
|
||||
|
||||
import cv2
|
||||
lock = threading.Lock()
|
||||
response = {'code': 0, 'data': 0}
|
||||
|
||||
@@ -31,27 +31,28 @@ if __name__ == "__main__":
|
||||
|
||||
# 配置日志输出
|
||||
logger.add(cfg['debug']['logger_filename'], format=cfg['debug']['logger_format'], retention = 5, level="INFO")
|
||||
camera_cfg = cfg['camera']
|
||||
|
||||
# 连接摄像头server 巡线只需要连接前摄像头
|
||||
context = zmq.Context()
|
||||
camera_socket = context.socket(zmq.SUB)
|
||||
camera_socket.connect(f"tcp://*:{camera_cfg['front_camera_port']}")
|
||||
camera_socket.setsockopt(zmq.SUBSCRIBE, '')
|
||||
camera_socket.connect(f"tcp://localhost:{cfg['camera']['front_camera_port']}")
|
||||
camera_socket.setsockopt_string(zmq.SUBSCRIBE, "")
|
||||
logger.info("connect camera success")
|
||||
# 初始化paddle推理器
|
||||
predictor = Lane_model_infer()
|
||||
logger.info("lane model load success")
|
||||
# 启动lane_infer_server线程
|
||||
mythread = threading.Thread(target=server_resp,
|
||||
args=(camera_cfg['lane_infer_port'],),
|
||||
args=(cfg['server']['lane_infer_port'],),
|
||||
daemon=True)
|
||||
mythread.start()
|
||||
|
||||
while True:
|
||||
image_data_bytes = camera_socket.recv(320*240)
|
||||
image = np.frombuffer(image_data_bytes, dtype=np.uint8).reshape((240, 320, 3))
|
||||
result = predictor.infer(image)
|
||||
message = camera_socket.recv()
|
||||
np_array = np.frombuffer(message, dtype=np.uint8)
|
||||
frame = cv2.imdecode(np_array, cv2.IMREAD_COLOR)
|
||||
frame = cv2.resize(frame,(320,240))
|
||||
result = predictor.infer(frame)
|
||||
with lock:
|
||||
response['data'] = result
|
||||
mythread.join()
|
||||
|
||||
19
lane_server/test_camera_recv.py
Normal file
19
lane_server/test_camera_recv.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import zmq
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.SUB)
|
||||
socket.connect("tcp://localhost:5555")
|
||||
socket.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||
|
||||
while True:
|
||||
message = socket.recv()
|
||||
np_array = np.frombuffer(message, dtype=np.uint8)
|
||||
frame = cv2.imdecode(np_array, cv2.IMREAD_COLOR)
|
||||
cv2.imshow("Received", frame)
|
||||
if cv2.waitKey(1) == 27:
|
||||
break
|
||||
|
||||
cv2.destroyAllWindows()
|
||||
Reference in New Issue
Block a user