zsl #7
|
|
@ -94,7 +94,6 @@ class IntelligentRecognitionProcess(Process):
|
|||
|
||||
|
||||
|
||||
|
||||
class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||
__slots__ = ()
|
||||
|
||||
|
|
@ -245,8 +244,7 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
|||
# 启动心跳线程
|
||||
hb_thread = self.start_heartbeat(fb_queue, hb_queue, request_id, analyse_type, context)
|
||||
|
||||
|
||||
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #7.0,
|
||||
# print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #7.0,
|
||||
# 加载算法模型
|
||||
model_array = get_model(msg, context, analyse_type)
|
||||
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #9.5
|
||||
|
|
@ -301,20 +299,31 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
|||
task_status[0] = 1
|
||||
for i, model in enumerate(model_array):
|
||||
model_conf, code = model
|
||||
model_param = model_conf[1]
|
||||
# (modeType, model_param, allowedList, names, rainbows)
|
||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||
model_conf)
|
||||
if draw_config.get("font_config") is None:
|
||||
draw_config["font_config"] = model_param['font_config']
|
||||
if draw_config.get(code) is None:
|
||||
draw_config[code] = {}
|
||||
draw_config[code]["allowedList"] = model_conf[2]
|
||||
draw_config[code]["rainbows"] = model_conf[4]
|
||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||
if "label_dict" in model_param:
|
||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno)
|
||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
||||
if draw_config.get(code) is None:
|
||||
draw_config[code] = {}
|
||||
draw_config["font_config"] = model_conf[4]
|
||||
draw_config[code]["allowedList"] = 0
|
||||
draw_config[code]["label_arrays"] = [None]
|
||||
draw_config[code]["rainbows"] = model_conf[4]
|
||||
else:
|
||||
model_param = model_conf[1]
|
||||
# (modeType, model_param, allowedList, names, rainbows)
|
||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||
model_conf)
|
||||
if draw_config.get("font_config") is None:
|
||||
draw_config["font_config"] = model_param['font_config']
|
||||
if draw_config.get(code) is None:
|
||||
draw_config[code] = {}
|
||||
draw_config[code]["allowedList"] = model_conf[2]
|
||||
draw_config[code]["rainbows"] = model_conf[4]
|
||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||
if "label_dict" in model_param:
|
||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||
|
||||
|
||||
# print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno)
|
||||
# 多线程并发处理, 经过测试两个线程最优
|
||||
det_array = []
|
||||
for i, frame in enumerate(frame_list):
|
||||
|
|
@ -616,19 +625,31 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
|||
task_status[0] = 1
|
||||
for i, model in enumerate(model_array):
|
||||
model_conf, code = model
|
||||
model_param = model_conf[1]
|
||||
# (modeType, model_param, allowedList, names, rainbows)
|
||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||
model_conf)
|
||||
if draw_config.get("font_config") is None:
|
||||
draw_config["font_config"] = model_param['font_config']
|
||||
if draw_config.get(code) is None:
|
||||
draw_config[code] = {}
|
||||
draw_config[code]["allowedList"] = model_conf[2]
|
||||
draw_config[code]["rainbows"] = model_conf[4]
|
||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||
if "label_dict" in model_param:
|
||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
||||
if draw_config.get(code) is None:
|
||||
draw_config[code] = {}
|
||||
draw_config["font_config"] = model_conf[4]
|
||||
draw_config[code]["allowedList"] = 0
|
||||
draw_config[code]["label_arrays"] = [None]
|
||||
draw_config[code]["rainbows"] = model_conf[4]
|
||||
|
||||
else:
|
||||
model_param = model_conf[1]
|
||||
# (modeType, model_param, allowedList, names, rainbows)
|
||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||
model_conf)
|
||||
if draw_config.get("font_config") is None:
|
||||
draw_config["font_config"] = model_param['font_config']
|
||||
if draw_config.get(code) is None:
|
||||
draw_config[code] = {}
|
||||
draw_config[code]["allowedList"] = model_conf[2]
|
||||
draw_config[code]["rainbows"] = model_conf[4]
|
||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||
if "label_dict" in model_param:
|
||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||
|
||||
|
||||
det_array = []
|
||||
for i, frame in enumerate(frame_list):
|
||||
det_result = t.submit(self.obj_det, self, model_array, frame, task_status,
|
||||
|
|
@ -922,6 +943,63 @@ class PhotosIntelligentRecognitionProcess(Process):
|
|||
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
||||
raise e
|
||||
|
||||
#自研究车牌模型
|
||||
def carplate_rec(self, imageUrl, mod, image_queue, request_id):
|
||||
try:
|
||||
# model_conf: modeType, allowedList, detpar, ocrmodel, rainbows
|
||||
model_conf, code = mod
|
||||
modeType, device, modelList, detpar, rainbows = model_conf
|
||||
image = url2Array(imageUrl)
|
||||
dets = {code: {}}
|
||||
# param = [image, new_device, model, par, img_type, request_id]
|
||||
# model_conf, frame, device, requestId
|
||||
dataBack = MODEL_CONFIG[code][3]([[modeType, device, modelList, detpar], image, request_id])[0][2]
|
||||
dets[code][0] = dataBack
|
||||
if not dataBack:
|
||||
logger.info("车牌识别为空")
|
||||
|
||||
# for ai_result in dataBack:
|
||||
# label, box = ai_result
|
||||
# color = rainbows
|
||||
|
||||
if len(dataBack) > 0:
|
||||
put_queue(image_queue, (1, (dets, imageUrl, image, rainbows, "")), timeout=2, is_ex=False)
|
||||
|
||||
except ServiceException as s:
|
||||
raise s
|
||||
except Exception as e:
|
||||
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
||||
raise e
|
||||
|
||||
#密集人群计数
|
||||
def denscrowdcount_rec(self, imageUrl, mod, image_queue, request_id):
|
||||
try:
|
||||
# model_conf: modeType, allowedList, detpar, ocrmodel, rainbows
|
||||
model_conf, code = mod
|
||||
modeType, device, model, postPar, rainbows = model_conf
|
||||
image = url2Array(imageUrl)
|
||||
dets = {code: {}}
|
||||
# param = [image, new_device, model, par, img_type, request_id]
|
||||
# model_conf, frame, device, requestId
|
||||
dataBack = MODEL_CONFIG[code][3]([[modeType, device, model, postPar], image, request_id])[0][2]
|
||||
logger.info("当前人数:{}", dataBack[0][0])
|
||||
dets[code][0] = dataBack
|
||||
if not dataBack:
|
||||
logger.info("当前页面无人")
|
||||
|
||||
# for ai_result in dataBack:
|
||||
# label, box = ai_result
|
||||
# color = rainbows
|
||||
|
||||
if len(dataBack) > 0:
|
||||
put_queue(image_queue, (1, (dets, imageUrl, image, rainbows, '')), timeout=2, is_ex=False)
|
||||
|
||||
except ServiceException as s:
|
||||
raise s
|
||||
except Exception as e:
|
||||
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
||||
raise e
|
||||
|
||||
'''
|
||||
# 防疫模型
|
||||
'''
|
||||
|
|
@ -936,6 +1014,26 @@ class PhotosIntelligentRecognitionProcess(Process):
|
|||
for r in obj_list:
|
||||
r.result(60)
|
||||
|
||||
# 自研车牌识别模型:
|
||||
def carpalteRec(self, imageUrls, model, image_queue, request_id):
|
||||
with ThreadPoolExecutor(max_workers=2) as t:
|
||||
obj_list = []
|
||||
for imageUrl in imageUrls:
|
||||
obj = t.submit(self.carplate_rec, imageUrl, model, image_queue, request_id)
|
||||
obj_list.append(obj)
|
||||
for r in obj_list:
|
||||
r.result(60)
|
||||
|
||||
# 密集人群计数:CITY_DENSECROWDCOUNT_MODEL
|
||||
def denscrowdcountRec(self, imageUrls, model, image_queue, request_id):
|
||||
with ThreadPoolExecutor(max_workers=2) as t:
|
||||
obj_list = []
|
||||
for imageUrl in imageUrls:
|
||||
obj = t.submit(self.denscrowdcount_rec, imageUrl, model, image_queue, request_id)
|
||||
obj_list.append(obj)
|
||||
for r in obj_list:
|
||||
r.result(60)
|
||||
|
||||
def image_recognition(self, imageUrl, mod, image_queue, logo, request_id):
|
||||
try:
|
||||
model_conf, code = mod
|
||||
|
|
@ -1168,6 +1266,14 @@ class PhotosIntelligentRecognitionProcess(Process):
|
|||
elif model[1] == ModelType.PLATE_MODEL.value[1]:
|
||||
result = t.submit(self.epidemicPrevention, imageUrls, model, base_dir, env, request_id)
|
||||
task_list.append(result)
|
||||
# 自研车牌模型
|
||||
elif model[1] == ModelType.CITY_CARPLATE_MODEL.value[1]:
|
||||
result = t.submit(self.carpalteRec, imageUrls, model, image_queue, request_id)
|
||||
task_list.append(result)
|
||||
# 人群计数模型
|
||||
elif model[1] == ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1]:
|
||||
result = t.submit(self.denscrowdcountRec, imageUrls, model, image_queue, request_id)
|
||||
task_list.append(result)
|
||||
else:
|
||||
result = t.submit(self.publicIdentification, imageUrls, model, image_queue, logo, request_id)
|
||||
task_list.append(result)
|
||||
|
|
@ -1380,9 +1486,6 @@ class ScreenRecordingProcess(Process):
|
|||
clear_queue(self._hb_queue)
|
||||
clear_queue(self._pull_queue)
|
||||
|
||||
|
||||
|
||||
|
||||
def upload_video(self,base_dir, env, request_id, orFilePath):
|
||||
if self._storage_source==1:
|
||||
minioSdk = MinioSdk(base_dir, env, request_id )
|
||||
|
|
|
|||
Loading…
Reference in New Issue