大数据AI视频独立显示

This commit is contained in:
jiangchaoqing 2025-07-26 14:17:01 +08:00
parent 855ba1bb40
commit 030d30e4e8
1 changed files with 56 additions and 97 deletions

View File

@ -23,7 +23,7 @@ from util.Cv2Utils import video_conjuncing, write_or_video, write_ai_video, push
from util.ImageUtils import url2Array, add_water_pic from util.ImageUtils import url2Array, add_water_pic
from util.LogUtils import init_log from util.LogUtils import init_log
from util.PlotsUtils import draw_painting_joint, filterBox, xywh2xyxy2, xy2xyxy, draw_name_joint, plot_one_box_auto, draw_name_ocr,draw_name_crowd from util.PlotsUtils import draw_painting_joint, filterBox, xywh2xyxy2, draw_name_joint
from util.QueUtil import get_no_block_queue, put_queue, clear_queue from util.QueUtil import get_no_block_queue, put_queue, clear_queue
@ -37,7 +37,7 @@ class PushStreamProcess(Process):
self._msg, self._push_queue, self._image_queue, self._push_ex_queue, self._hb_queue, self._context = args self._msg, self._push_queue, self._image_queue, self._push_ex_queue, self._hb_queue, self._context = args
self._algStatus = False # 默认关闭 self._algStatus = False # 默认关闭
self._algSwitch = self._context['service']['algSwitch'] self._algSwitch = self._context['service']['algSwitch']
#0521: #0521:
default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true" default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true"
@ -49,9 +49,16 @@ class PushStreamProcess(Process):
print("执行替代程序defaultEnabled=False") print("执行替代程序defaultEnabled=False")
# 这里放非默认逻辑的代码 # 这里放非默认逻辑的代码
self._algSwitch = False self._algSwitch = False
print("---line53 :PushVideoStreamProcess.py---",self._algSwitch) print("---line53 :PushVideoStreamProcess.py---",self._algSwitch)
def build_logo_url(self): def build_logo_url(self):
logo = None logo = None
if self._context["video"]["video_add_water"]: if self._context["video"]["video_add_water"]:
@ -148,39 +155,17 @@ class OnPushStreamProcess(PushStreamProcess):
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"] font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"] rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
for qs in det_result: for qs in det_result:
# 自研车牌模型处理 try: # 应对NaN情况
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code): box, score, cls = xywh2xyxy2(qs)
cls = 0 except:
ocrlabel, xybox = qs continue
box = xy2xyxy(xybox) if cls not in allowedList or score < frame_score:
score = None continue
color = rainbows[cls] label_array, color = label_arrays[cls], rainbows[cls]
label_array = None if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
rr = t.submit(draw_name_ocr, xybox, copy_frame, color, ocrlabel) rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
cls = 0
crowdlabel, points = qs
box = [(0, 0), (0, 0), (0, 0), (0, 0)]
score = None
color = rainbows[cls]
label_array = None
rr = t.submit(draw_name_crowd, points, copy_frame, color, crowdlabel)
else: else:
try: # 应对NaN情况 rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
box, score, cls = xywh2xyxy2(qs)
except:
continue
if cls not in allowedList or score < frame_score:
continue
label_array, color = label_arrays[cls], rainbows[cls]
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
rr = t.submit(draw_name_joint, box, copy_frame,
draw_config[code]["label_dict"], score, color,
font_config, qs[6])
else:
rr = t.submit(draw_painting_joint, box, copy_frame, label_array,
score, color, font_config)
thread_p.append(rr) thread_p.append(rr)
if det_xywh.get(code) is None: if det_xywh.get(code) is None:
det_xywh[code] = {} det_xywh[code] = {}
@ -199,18 +184,22 @@ class OnPushStreamProcess(PushStreamProcess):
box[2][0], box[2][1], box[3][0], box[3][1], box[2][0], box[2][1], box[3][0], box[3][1],
score, cls, code],dtype=np.float32) score, cls, code],dtype=np.float32)
qs_np = np.row_stack((qs_np, result_li)) qs_np = np.row_stack((qs_np, result_li))
if logo: if logo:
frame = add_water_pic(frame, logo, request_id) frame = add_water_pic(frame, logo, request_id)
copy_frame = add_water_pic(copy_frame, logo, request_id) copy_frame = add_water_pic(copy_frame, logo, request_id)
if len(thread_p) > 0: if len(thread_p) > 0:
for r in thread_p: for r in thread_p:
r.result() r.result()
#print('----line173:',self._algSwitch,self._algStatus) #print('----line173:',self._algSwitch,self._algStatus)
if self._algSwitch and (not self._algStatus): if self._algSwitch and (not self._algStatus):
frame_merge = video_conjuncing(frame, frame.copy()) # frame_merge = video_conjuncing(frame, frame.copy())
else:
frame_merge = video_conjuncing(frame, copy_frame) frame_merge = frame.copy()
else:
# frame_merge = video_conjuncing(frame, copy_frame)
frame_merge = copy_frame
# 写原视频到本地 # 写原视频到本地
write_or_video_result = t.submit(write_or_video, frame, orFilePath, or_video_file, write_or_video_result = t.submit(write_or_video, frame, orFilePath, or_video_file,
or_write_status, request_id) or_write_status, request_id)
@ -222,7 +211,7 @@ class OnPushStreamProcess(PushStreamProcess):
# 如果有问题, 走下面的逻辑 # 如果有问题, 走下面的逻辑
if qs_np is not None: if qs_np is not None:
if len(qs_np.shape) == 1: if len(qs_np.shape) == 1:
qs_np = qs_np[np.newaxis,...] qs_np = qs_np[np.newaxis,...]
qs_np_id = qs_np.copy() qs_np_id = qs_np.copy()
b = np.ones(qs_np_id.shape[0]) b = np.ones(qs_np_id.shape[0])
qs_np_id = np.column_stack((qs_np_id,b)) qs_np_id = np.column_stack((qs_np_id,b))
@ -248,7 +237,7 @@ class OnPushStreamProcess(PushStreamProcess):
if q[11] >= 1: if q[11] >= 1:
cls = int(q[9]) cls = int(q[9])
if not (cls in new_lab): if not (cls in new_lab):
continue # 为了防止其他类别被带出 continue # 为了防止其他类别被带出
code = str(int(q[10])).zfill(3) code = str(int(q[10])).zfill(3)
if det_xywh2.get(code) is None: if det_xywh2.get(code) is None:
det_xywh2[code] = {} det_xywh2[code] = {}
@ -261,11 +250,6 @@ class OnPushStreamProcess(PushStreamProcess):
is_new = False is_new = False
if q[11] == 1: if q[11] == 1:
is_new = True is_new = True
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
cls = ocrlabel
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
cls = crowdlabel
label_array = points
if cd is None: if cd is None:
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]] det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
else: else:
@ -288,7 +272,7 @@ class OnPushStreamProcess(PushStreamProcess):
ex_status = False ex_status = False
logger.info("停止推流进程, requestId: {}", request_id) logger.info("停止推流进程, requestId: {}", request_id)
break break
del push_r del push_r
else: else:
sleep(1) sleep(1)
@ -383,45 +367,24 @@ class OffPushStreamProcess(PushStreamProcess):
qs_reurn = [] qs_reurn = []
for det in push_objs[i]: for det in push_objs[i]:
code, det_result = det code, det_result = det
# 每个单独模型处理 # 每个单独模型处理
# 模型编号、100帧的所有问题, 检测目标、颜色、文字图片 # 模型编号、100帧的所有问题, 检测目标、颜色、文字图片
if len(det_result) > 0: if len(det_result) > 0:
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"] font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"] rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
for qs in det_result: for qs in det_result:
# 自研车牌模型处理 box, score, cls = xywh2xyxy2(qs)
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
cls = 0 if cls not in allowedList or score < frame_score:
ocrlabel, xybox = qs continue
box = xy2xyxy(xybox) label_array, color = label_arrays[cls], rainbows[cls]
score = None if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
color = rainbows[cls] rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
label_array = None
label_arrays = [None]
rr = t.submit(draw_name_ocr,xybox,copy_frame,color,ocrlabel)
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
cls = 0
crowdlabel, points = qs
box = [(0,0),(0,0),(0,0),(0,0)]
score = None
color = rainbows[cls]
label_array = None
rr = t.submit(draw_name_crowd, points, copy_frame, color, crowdlabel)
else: else:
box, score, cls = xywh2xyxy2(qs) rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
if cls not in allowedList or score < frame_score:
continue
label_array, color = label_arrays[cls], rainbows[cls]
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
else:
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
thread_p.append(rr) thread_p.append(rr)
if det_xywh.get(code) is None: if det_xywh.get(code) is None:
det_xywh[code] = {} det_xywh[code] = {}
cd = det_xywh[code].get(cls) cd = det_xywh[code].get(cls)
@ -429,17 +392,17 @@ class OffPushStreamProcess(PushStreamProcess):
if cd is None: if cd is None:
det_xywh[code][cls] = [[cls, box, score, label_array, color]] det_xywh[code][cls] = [[cls, box, score, label_array, color]]
else: else:
det_xywh[code][cls].append([cls, box, score, label_array, color]) det_xywh[code][cls].append([cls, box, score, label_array, color])
if qs_np is None: if qs_np is None:
qs_np = np.array([box[0][0], box[0][1], box[1][0], box[1][1], qs_np = np.array([box[0][0], box[0][1], box[1][0], box[1][1],
box[2][0], box[2][1], box[3][0], box[3][1], box[2][0], box[2][1], box[3][0], box[3][1],
score, cls, code],dtype=np.float32) score, cls, code],dtype=np.float32)
else: else:
result_li = np.array([box[0][0], box[0][1], box[1][0], box[1][1], result_li = np.array([box[0][0], box[0][1], box[1][0], box[1][1],
box[2][0], box[2][1], box[3][0], box[3][1], box[2][0], box[2][1], box[3][0], box[3][1],
score, cls, code],dtype=np.float32) score, cls, code],dtype=np.float32)
qs_np = np.row_stack((qs_np, result_li)) qs_np = np.row_stack((qs_np, result_li))
if logo: if logo:
frame = add_water_pic(frame, logo, request_id) frame = add_water_pic(frame, logo, request_id)
copy_frame = add_water_pic(copy_frame, logo, request_id) copy_frame = add_water_pic(copy_frame, logo, request_id)
@ -447,9 +410,11 @@ class OffPushStreamProcess(PushStreamProcess):
for r in thread_p: for r in thread_p:
r.result() r.result()
if self._algSwitch and (not self._algStatus): if self._algSwitch and (not self._algStatus):
frame_merge = video_conjuncing(frame, frame.copy()) # frame_merge = video_conjuncing(frame, frame.copy())
else: frame_merge = frame.copy()
frame_merge = video_conjuncing(frame, copy_frame) else:
# frame_merge = video_conjuncing(frame, copy_frame)
frame_merge = copy_frame
# 写识别视频到本地 # 写识别视频到本地
write_ai_video_result = t.submit(write_ai_video, frame_merge, aiFilePath, write_ai_video_result = t.submit(write_ai_video, frame_merge, aiFilePath,
ai_video_file, ai_video_file,
@ -457,9 +422,10 @@ class OffPushStreamProcess(PushStreamProcess):
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url, push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url,
p_push_status, request_id) p_push_status, request_id)
if qs_np is not None: if qs_np is not None:
if len(qs_np.shape) == 1: if len(qs_np.shape) == 1:
qs_np = qs_np[np.newaxis,...] qs_np = qs_np[np.newaxis,...]
qs_np_id = qs_np.copy() qs_np_id = qs_np.copy()
b = np.ones(qs_np_id.shape[0]) b = np.ones(qs_np_id.shape[0])
qs_np_id = np.column_stack((qs_np_id,b)) qs_np_id = np.column_stack((qs_np_id,b))
@ -486,7 +452,7 @@ class OffPushStreamProcess(PushStreamProcess):
if q[11] >= 1: if q[11] >= 1:
cls = int(q[9]) cls = int(q[9])
if not (cls in new_lab): if not (cls in new_lab):
continue # 为了防止其他类别被带出 continue # 为了防止其他类别被带出
code = str(int(q[10])).zfill(3) code = str(int(q[10])).zfill(3)
if det_xywh2.get(code) is None: if det_xywh2.get(code) is None:
det_xywh2[code] = {} det_xywh2[code] = {}
@ -499,13 +465,6 @@ class OffPushStreamProcess(PushStreamProcess):
is_new = False is_new = False
if q[11] == 1: if q[11] == 1:
is_new = True is_new = True
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
cls = ocrlabel
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
cls = crowdlabel
label_array = points
if cd is None: if cd is None:
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]] det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
else: else: