import requests
import re
import json
json_url = 'http://192.168.172.100:23333' # 修改为darknet的json流地址
while True:
conn = requests.get(json_url, stream=True, timeout=50)
for json_dict in conn.iter_lines():
if 'frame_id' in json_dict.decode('utf-8'):
frame_id = int(re.findall(r"frame_id.{0,2}([0-9]+)", json_dict.decode('utf-8'))[0])
print('frame_id: ', frame_id, json_dict.decode('utf-8'))
if len(json_dict)>7 and 'class_id' in json_dict.decode('utf-8'):
json_dict = re.findall(r'{.*}', json_dict.decode('utf-8'))
if json_dict:
json_dict = json.loads(json_dict[0])
#print(json_dict['relative_coordinates']['center_x'], json_dict['relative_coordinates']['center_y'], \
#json_dict['relative_coordinates']['width'], json_dict['relative_coordinates']['height'])
else:
continue
print('the END! json_dict:{}'.format(json_dict))
python获取darknet的json流
最新推荐文章于 2021-04-15 18:38:17 发布