@@ -32,7 +32,7 @@ class ImageFileUpload(FileUpload): | |||
def handle_image(frame_msg, frame_step): | |||
# (high_score_image["code"], all_frames, draw_config["font_config"]) | |||
# high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) | |||
det_result, all_frames, font_config = frame_msg | |||
det_xywh, frame, current_frame, all_frames, font_config = frame_msg | |||
''' | |||
det_xywh:{ | |||
'code':{ | |||
@@ -44,62 +44,24 @@ class ImageFileUpload(FileUpload): | |||
''' | |||
model_info = [] | |||
# 更加模型编码解析数据 | |||
for code, det_list in det_result.items(): | |||
for code, det_list in det_xywh.items(): | |||
if len(det_list) > 0: | |||
for cls, target_list in det_list.items(): | |||
frame, iframe, cls_list = target_list | |||
if len(cls_list) > 0: | |||
if len(target_list) > 0: | |||
aFrame = frame.copy() | |||
for target in cls_list: | |||
# detect_targets_code, box, score, label_array, color | |||
for target in target_list: | |||
draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config) | |||
model_info.append({ | |||
"or_frame": frame, | |||
"modelCode": str(code), | |||
"detectTargetCode": str(cls), | |||
"aFrame": aFrame, | |||
"current_frame": iframe, | |||
"last_frame": iframe + frame_step | |||
}) | |||
model_info.append({"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame}) | |||
if len(model_info) > 0: | |||
return model_info | |||
image_result = { | |||
"or_frame": frame, | |||
"model_info": model_info, | |||
"current_frame": current_frame, | |||
"last_frame": current_frame + frame_step | |||
} | |||
return image_result | |||
return None | |||
# @staticmethod | |||
# def handle_image(frame_msg, frame_step): | |||
# # (high_score_image["code"], all_frames, draw_config["font_config"]) | |||
# # high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) | |||
# det_xywh, frame, current_frame, all_frames, font_config = frame_msg | |||
# ''' | |||
# det_xywh:{ | |||
# 'code':{ | |||
# 1: [[detect_targets_code, box, score, label_array, color]] | |||
# } | |||
# } | |||
# 模型编号:modeCode | |||
# 检测目标:detectTargetCode | |||
# ''' | |||
# model_info = [] | |||
# # 更加模型编码解析数据 | |||
# for code, det_list in det_xywh.items(): | |||
# if len(det_list) > 0: | |||
# for cls, target_list in det_list.items(): | |||
# if len(target_list) > 0: | |||
# aFrame = frame.copy() | |||
# for target in target_list: | |||
# # detect_targets_code, box, score, label_array, color | |||
# draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config) | |||
# model_info.append({"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame}) | |||
# if len(model_info) > 0: | |||
# image_result = { | |||
# "or_frame": frame, | |||
# "model_info": model_info, | |||
# "current_frame": current_frame, | |||
# "last_frame": current_frame + frame_step | |||
# } | |||
# return image_result | |||
# return None | |||
def run(self): | |||
msg, context = self._msg, self._context | |||
service = context["service"] | |||
@@ -129,18 +91,20 @@ class ImageFileUpload(FileUpload): | |||
if image_msg[0] == 1: | |||
image_result = self.handle_image(image_msg[1], frame_step) | |||
if image_result is not None: | |||
task, msg_list = [], [] | |||
for model_info in image_result: | |||
or_image = cv2.imencode(".jpg", model_info["or_frame"])[1] | |||
or_image_name = build_image_name(model_info["current_frame"], | |||
model_info["last_frame"], | |||
analyse_type, | |||
"OR", "0", "0", request_id) | |||
or_future = t.submit(aliyunOssSdk.put_object, or_image_name, or_image.tobytes()) | |||
task.append(or_future) | |||
task = [] | |||
or_image = cv2.imencode(".jpg", image_result["or_frame"])[1] | |||
or_image_name = build_image_name(image_result["current_frame"], | |||
image_result["last_frame"], | |||
analyse_type, | |||
"OR", "0", "0", request_id) | |||
or_future = t.submit(aliyunOssSdk.put_object, or_image_name, or_image.tobytes()) | |||
task.append(or_future) | |||
model_info_list = image_result["model_info"] | |||
msg_list = [] | |||
for model_info in model_info_list: | |||
ai_image = cv2.imencode(".jpg", model_info["aFrame"])[1] | |||
ai_image_name = build_image_name(model_info["current_frame"], | |||
model_info["last_frame"], | |||
ai_image_name = build_image_name(image_result["current_frame"], | |||
image_result["last_frame"], | |||
analyse_type, | |||
"AI", | |||
model_info["modelCode"], | |||
@@ -161,40 +125,6 @@ class ImageFileUpload(FileUpload): | |||
for msg in msg_list: | |||
put_queue(fb_queue, msg, timeout=2, is_ex=False) | |||
del task, msg_list | |||
# task = [] | |||
# or_image = cv2.imencode(".jpg", image_result["or_frame"])[1] | |||
# or_image_name = build_image_name(image_result["current_frame"], | |||
# image_result["last_frame"], | |||
# analyse_type, | |||
# "OR", "0", "0", request_id) | |||
# or_future = t.submit(aliyunOssSdk.put_object, or_image_name, or_image.tobytes()) | |||
# task.append(or_future) | |||
# model_info_list = image_result["model_info"] | |||
# msg_list = [] | |||
# for model_info in model_info_list: | |||
# ai_image = cv2.imencode(".jpg", model_info["aFrame"])[1] | |||
# ai_image_name = build_image_name(image_result["current_frame"], | |||
# image_result["last_frame"], | |||
# analyse_type, | |||
# "AI", | |||
# model_info["modelCode"], | |||
# model_info["detectTargetCode"], | |||
# request_id) | |||
# ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name, | |||
# ai_image.tobytes()) | |||
# task.append(ai_future) | |||
# msg_list.append(message_feedback(request_id, | |||
# AnalysisStatus.RUNNING.value, | |||
# analyse_type, "", "", "", | |||
# or_image_name, | |||
# ai_image_name, | |||
# model_info['modelCode'], | |||
# model_info['detectTargetCode'])) | |||
# for tk in task: | |||
# tk.result() | |||
# for msg in msg_list: | |||
# put_queue(fb_queue, msg, timeout=2, is_ex=False) | |||
# del task, msg_list | |||
else: | |||
sleep(1) | |||
del image_msg |
@@ -133,6 +133,7 @@ class OnlinePullVideoStreamProcess(PullVideoStreamProcess): | |||
ExceptionType.NO_RESOURCES.value[0], | |||
ExceptionType.NO_RESOURCES.value[1]), timeout=2) | |||
break | |||
del frame | |||
continue | |||
full_timeout = None | |||
if frame is None: |
@@ -161,6 +161,7 @@ class OnlinePullVideoStreamProcess2(PullVideoStreamProcess2): | |||
ExceptionType.NO_RESOURCES.value[0], | |||
ExceptionType.NO_RESOURCES.value[1])) | |||
break | |||
del frame | |||
continue | |||
full_timeout = None | |||
frame_list.append(frame) |
@@ -154,68 +154,27 @@ class OnPushStreamProcess(PushStreamProcess): | |||
ai_video_file, ai_write_status, request_id) | |||
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url, | |||
p_push_status, request_id) | |||
# 指定多少帧上传一次问题 | |||
if high_score_image.get("current_frame") is None: | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
diff_frame_num = frame_index_list[i] - high_score_image["current_frame"] | |||
# 指定帧内处理逻辑 | |||
if frame_step >= diff_frame_num and high_score_image.get("code") is not None and len(det_xywh) > 0: | |||
# 所有的模型编号 | |||
cache_codes = set(high_score_image["code"].keys()) | |||
# 遍历当前模型 | |||
for det_code, det_clss in det_xywh.items(): | |||
# 如果模型编号不在缓存中 | |||
if det_code not in cache_codes: | |||
high_score_image["code"][det_code] = {} | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
# 如果模型编号在缓存中, 检查检测目标的情况 | |||
cache_clss = set(high_score_image["code"][det_code].keys()) | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
if cls not in cache_clss: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
if len(det_xywh[det_code][cls]) > len(high_score_image["code"][det_code][cls][2]): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
elif len(det_xywh[det_code][cls]) == len(high_score_image["code"][det_code][cls][2]): | |||
# [cls, box, score, label_array, color] | |||
hs = 0 | |||
for ii, s in enumerate(cls_list): | |||
if s[2] >= high_score_image["code"][det_code][cls][2][ii][2]: | |||
hs += 1 | |||
if hs == len(cls_list): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
if diff_frame_num > frame_step: | |||
if high_score_image.get("code") is not None: | |||
high_score_image["or_frame"] = frame | |||
put_queue(image_queue, (1, [high_score_image["code"], all_frames, draw_config["font_config"]])) | |||
high_score_image["code"] = None | |||
high_score_image["current_frame"] = None | |||
# 如果有问题, 走下面的逻辑 | |||
if len(det_xywh) > 0: | |||
flag = True | |||
# 比较上一次识别到问题的帧和当前问题帧的相似度 | |||
if picture_similarity and high_score_image.get("or_frame") is not None: | |||
hash1 = ImageUtils.dHash(high_score_image["or_frame"]) | |||
if picture_similarity and len(high_score_image) > 0: | |||
hash1 = ImageUtils.dHash(high_score_image.get("or_frame")) | |||
hash2 = ImageUtils.dHash(frame) | |||
dist = ImageUtils.Hamming_distance(hash1, hash2) | |||
similarity_1 = 1 - dist * 1.0 / 64 | |||
if similarity_1 >= similarity: | |||
flag = False | |||
# 如果缓存问题是空的,给缓存添加问题 | |||
if flag and high_score_image.get("code") is None: | |||
high_score_image["code"] = {} | |||
for code, det_list in det_xywh.items(): | |||
if high_score_image["code"].get(code) is None: | |||
high_score_image["code"][code] = {} | |||
for cls, cls_list in det_list.items(): | |||
high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) | |||
push_p = push_stream_result.result(timeout=5) | |||
ai_video_file = write_ai_video_result.result(timeout=5) | |||
or_video_file = write_or_video_result.result(timeout=5) | |||
if len(high_score_image) > 0: | |||
diff_frame_num = frame_index_list[i] - high_score_image.get("current_frame") | |||
if diff_frame_num < frame_step: | |||
flag = False | |||
if flag: | |||
high_score_image["or_frame"] = frame | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
put_queue(image_queue, (1, [det_xywh, frame, frame_index_list[i], all_frames, draw_config["font_config"]])) | |||
push_p = push_stream_result.result(timeout=60) | |||
ai_video_file = write_ai_video_result.result(timeout=60) | |||
or_video_file = write_or_video_result.result(timeout=60) | |||
# 接收停止指令 | |||
if push_r[0] == 2: | |||
if 'stop' == push_r[1]: | |||
@@ -248,7 +207,7 @@ class OnPushStreamProcess(PushStreamProcess): | |||
if image_queue.qsize() == 0 or image_queue.empty(): | |||
break | |||
sleep(2) | |||
for q in [push_queue, image_queue, push_ex_queue, hb_queue]: | |||
for q in [push_queue, image_queue, hb_queue]: | |||
clear_queue(q) | |||
logger.info("推流进程停止完成!图片队列大小: {}, requestId:{}", image_queue.qsize(), request_id) | |||
@@ -346,68 +305,26 @@ class OffPushStreamProcess(PushStreamProcess): | |||
ai_write_status, request_id) | |||
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url, | |||
p_push_status, request_id) | |||
# 指定多少帧上传一次问题 | |||
if high_score_image.get("current_frame") is None: | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
diff_frame_num = frame_index_list[i] - high_score_image["current_frame"] | |||
# 指定帧内处理逻辑 | |||
if frame_step >= diff_frame_num and high_score_image.get("code") is not None and len(det_xywh) > 0: | |||
# 所有的模型编号 | |||
cache_codes = set(high_score_image["code"].keys()) | |||
# 遍历当前模型 | |||
for det_code, det_clss in det_xywh.items(): | |||
# 如果模型编号不在缓存中 | |||
if det_code not in cache_codes: | |||
high_score_image["code"][det_code] = {} | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
# 如果模型编号在缓存中, 检查检测目标的情况 | |||
cache_clss = set(high_score_image["code"][det_code].keys()) | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
# 如果检测目标在缓存中 | |||
if cls not in cache_clss: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
if len(det_xywh[det_code][cls]) > len(high_score_image["code"][det_code][cls][2]): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
elif len(det_xywh[det_code][cls]) == len(high_score_image["code"][det_code][cls][2]): | |||
# [cls, box, score, label_array, color] | |||
hs = 0 | |||
for ii, s in enumerate(cls_list): | |||
if s[2] >= high_score_image["code"][det_code][cls][2][ii][2]: | |||
hs += 1 | |||
if hs == len(cls_list): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
if diff_frame_num > frame_step: | |||
if high_score_image.get("code") is not None: | |||
high_score_image["or_frame"] = frame | |||
put_queue(image_queue, (1, [high_score_image["code"], all_frames, draw_config["font_config"]])) | |||
high_score_image["code"] = None | |||
high_score_image["current_frame"] = None | |||
# 如果有问题, 走下面的逻辑 | |||
if len(det_xywh) > 0: | |||
flag = True | |||
# 比较上一次识别到问题的帧和当前问题帧的相似度 | |||
if picture_similarity and high_score_image.get("or_frame") is not None: | |||
hash1 = ImageUtils.dHash(high_score_image["or_frame"]) | |||
if picture_similarity and len(high_score_image) > 0: | |||
hash1 = ImageUtils.dHash(high_score_image.get("or_frame")) | |||
hash2 = ImageUtils.dHash(frame) | |||
dist = ImageUtils.Hamming_distance(hash1, hash2) | |||
similarity_1 = 1 - dist * 1.0 / 64 | |||
if similarity_1 >= similarity: | |||
flag = False | |||
# 如果缓存问题是空的,给缓存添加问题 | |||
if flag and high_score_image.get("code") is None: | |||
high_score_image["code"] = {} | |||
for code, det_list in det_xywh.items(): | |||
if high_score_image["code"].get(code) is None: | |||
high_score_image["code"][code] = {} | |||
for cls, cls_list in det_list.items(): | |||
high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) | |||
push_p = push_stream_result.result(timeout=5) | |||
ai_video_file = write_ai_video_result.result(timeout=5) | |||
if len(high_score_image) > 0: | |||
diff_frame_num = frame_index_list[i] - high_score_image.get("current_frame") | |||
if diff_frame_num < frame_step: | |||
flag = False | |||
if flag: | |||
high_score_image["or_frame"] = frame | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
put_queue(image_queue, (1, [det_xywh, frame, frame_index_list[i], all_frames, draw_config["font_config"]])) | |||
push_p = push_stream_result.result(timeout=60) | |||
ai_video_file = write_ai_video_result.result(timeout=60) | |||
# 接收停止指令 | |||
if push_r[0] == 2: | |||
if 'stop' == push_r[1]: | |||
@@ -440,6 +357,6 @@ class OffPushStreamProcess(PushStreamProcess): | |||
if image_queue.qsize() == 0 or image_queue.empty(): | |||
break | |||
sleep(2) | |||
for q in [push_queue, image_queue, push_ex_queue, hb_queue]: | |||
for q in [push_queue, image_queue, hb_queue]: | |||
clear_queue(q) | |||
logger.info("推流进程停止完成!requestId:{}", request_id) |
@@ -137,69 +137,26 @@ class OnPushStreamProcess2(PushStreamProcess2): | |||
push_p_result = t.submit(push_video_stream, frame_merge, push_p, push_url, | |||
p_push_status, | |||
request_id) | |||
# 指定多少帧上传一次问题 | |||
if high_score_image.get("current_frame") is None: | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
diff_frame_num = frame_index_list[i] - high_score_image["current_frame"] | |||
# 指定帧内处理逻辑 | |||
if frame_step >= diff_frame_num and high_score_image.get("code") is not None and len(det_xywh) > 0: | |||
# 所有的模型编号 | |||
cache_codes = set(high_score_image["code"].keys()) | |||
# 遍历当前模型 | |||
for det_code, det_clss in det_xywh.items(): | |||
# 如果模型编号不在缓存中 | |||
if det_code not in cache_codes: | |||
high_score_image["code"][det_code] = {} | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
# 如果模型编号在缓存中, 检查检测目标的情况 | |||
cache_clss = set(high_score_image["code"][det_code].keys()) | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
# 如果检测目标在缓存中 | |||
if cls not in cache_clss: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
if len(det_xywh[det_code][cls]) > len(high_score_image["code"][det_code][cls][2]): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
elif len(det_xywh[det_code][cls]) == len(high_score_image["code"][det_code][cls][2]): | |||
# [cls, box, score, label_array, color] | |||
hs = 0 | |||
for ii, s in enumerate(cls_list): | |||
if s[2] >= high_score_image["code"][det_code][cls][2][ii][2]: | |||
hs += 1 | |||
if hs == len(cls_list): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
if diff_frame_num > frame_step: | |||
if high_score_image.get("code") is not None: | |||
high_score_image["or_frame"] = frame | |||
put_queue(image_queue, (1, [high_score_image["code"], all_frames, draw_config["font_config"]])) | |||
high_score_image["code"] = None | |||
high_score_image["current_frame"] = None | |||
# 如果有问题, 走下面的逻辑 | |||
if len(det_xywh) > 0: | |||
flag = True | |||
# 比较上一次识别到问题的帧和当前问题帧的相似度 | |||
if picture_similarity and high_score_image.get("or_frame") is not None: | |||
hash1 = ImageUtils.dHash(high_score_image["or_frame"]) | |||
if picture_similarity and len(high_score_image) > 0: | |||
hash1 = ImageUtils.dHash(high_score_image.get("or_frame")) | |||
hash2 = ImageUtils.dHash(frame) | |||
dist = ImageUtils.Hamming_distance(hash1, hash2) | |||
similarity_1 = 1 - dist * 1.0 / 64 | |||
if similarity_1 >= similarity: | |||
flag = False | |||
# 如果缓存问题是空的,给缓存添加问题 | |||
if flag and high_score_image.get("code") is None: | |||
high_score_image["code"] = {} | |||
for code, det_list in det_xywh.items(): | |||
if high_score_image["code"].get(code) is None: | |||
high_score_image["code"][code] = {} | |||
for cls, cls_list in det_list.items(): | |||
high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) | |||
push_p = push_p_result.result(timeout=5) | |||
ai_video_file = write_ai_video_result.result(timeout=5) | |||
or_video_file = write_or_video_result.result(timeout=5) | |||
if len(high_score_image) > 0: | |||
diff_frame_num = frame_index_list[i] - high_score_image.get("current_frame") | |||
if diff_frame_num < frame_step: | |||
flag = False | |||
if flag: | |||
high_score_image["or_frame"] = frame | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
put_queue(image_queue, (1, [det_xywh, frame, frame_index_list[i], all_frames, draw_config["font_config"]])) | |||
push_p = push_p_result.result(timeout=60) | |||
ai_video_file = write_ai_video_result.result(timeout=60) | |||
or_video_file = write_or_video_result.result(timeout=60) | |||
# 接收停止指令 | |||
if push_r[0] == 2: | |||
if 'stop' == push_r[1]: | |||
@@ -232,7 +189,7 @@ class OnPushStreamProcess2(PushStreamProcess2): | |||
if image_queue.qsize() == 0 or image_queue.empty(): | |||
break | |||
sleep(2) | |||
for q in [push_queue, image_queue, push_ex_queue, hb_queue]: | |||
for q in [push_queue, image_queue, hb_queue]: | |||
clear_queue(q) | |||
logger.info("推流进程停止完成!requestId:{}", request_id) | |||
@@ -329,68 +286,25 @@ class OffPushStreamProcess2(PushStreamProcess2): | |||
push_p_result = t.submit(push_video_stream, frame_merge, push_p, push_url, | |||
p_push_status, | |||
request_id) | |||
# 指定多少帧上传一次问题 | |||
if high_score_image.get("current_frame") is None: | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
diff_frame_num = frame_index_list[i] - high_score_image["current_frame"] | |||
# 指定帧内处理逻辑 | |||
if frame_step >= diff_frame_num and high_score_image.get("code") is not None and len(det_xywh) > 0: | |||
# 所有的模型编号 | |||
cache_codes = set(high_score_image["code"].keys()) | |||
# 遍历当前模型 | |||
for det_code, det_clss in det_xywh.items(): | |||
# 如果模型编号不在缓存中 | |||
if det_code not in cache_codes: | |||
high_score_image["code"][det_code] = {} | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
# 如果模型编号在缓存中, 检查检测目标的情况 | |||
cache_clss = set(high_score_image["code"][det_code].keys()) | |||
for cls, cls_list in det_xywh[det_code].items(): | |||
if len(cls_list) > 0: | |||
# 如果检测目标在缓存中 | |||
if cls not in cache_clss: | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
else: | |||
if len(det_xywh[det_code][cls]) > len(high_score_image["code"][det_code][cls][2]): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
elif len(det_xywh[det_code][cls]) == len(high_score_image["code"][det_code][cls][2]): | |||
# [cls, box, score, label_array, color] | |||
hs = 0 | |||
for ii, s in enumerate(cls_list): | |||
if s[2] >= high_score_image["code"][det_code][cls][2][ii][2]: | |||
hs += 1 | |||
if hs == len(cls_list): | |||
high_score_image["code"][det_code][cls] = (frame, frame_index_list[i], cls_list) | |||
if diff_frame_num > frame_step: | |||
if high_score_image.get("code") is not None: | |||
high_score_image["or_frame"] = frame | |||
put_queue(image_queue, (1, [high_score_image["code"], all_frames, draw_config["font_config"]])) | |||
high_score_image["code"] = None | |||
high_score_image["current_frame"] = None | |||
# 如果有问题, 走下面的逻辑 | |||
if len(det_xywh) > 0: | |||
flag = True | |||
# 比较上一次识别到问题的帧和当前问题帧的相似度 | |||
if picture_similarity and high_score_image.get("or_frame") is not None: | |||
hash1 = ImageUtils.dHash(high_score_image["or_frame"]) | |||
if picture_similarity and len(high_score_image) > 0: | |||
hash1 = ImageUtils.dHash(high_score_image.get("or_frame")) | |||
hash2 = ImageUtils.dHash(frame) | |||
dist = ImageUtils.Hamming_distance(hash1, hash2) | |||
similarity_1 = 1 - dist * 1.0 / 64 | |||
if similarity_1 >= similarity: | |||
flag = False | |||
# 如果缓存问题是空的,给缓存添加问题 | |||
if flag and high_score_image.get("code") is None: | |||
high_score_image["code"] = {} | |||
for code, det_list in det_xywh.items(): | |||
if high_score_image["code"].get(code) is None: | |||
high_score_image["code"][code] = {} | |||
for cls, cls_list in det_list.items(): | |||
high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) | |||
push_p = push_p_result.result(timeout=5) | |||
ai_video_file = write_ai_video_result.result(timeout=5) | |||
if len(high_score_image) > 0: | |||
diff_frame_num = frame_index_list[i] - high_score_image.get("current_frame") | |||
if diff_frame_num < frame_step: | |||
flag = False | |||
if flag: | |||
high_score_image["or_frame"] = frame | |||
high_score_image["current_frame"] = frame_index_list[i] | |||
put_queue(image_queue, (1, [det_xywh, frame, frame_index_list[i], all_frames, draw_config["font_config"]])) | |||
push_p = push_p_result.result(timeout=60) | |||
ai_video_file = write_ai_video_result.result(timeout=60) | |||
# 接收停止指令 | |||
if push_r[0] == 2: | |||
if 'stop' == push_r[1]: | |||
@@ -423,6 +337,6 @@ class OffPushStreamProcess2(PushStreamProcess2): | |||
if image_queue.qsize() == 0 or image_queue.empty(): | |||
break | |||
sleep(2) | |||
for q in [push_queue, image_queue, push_ex_queue, hb_queue]: | |||
for q in [push_queue, image_queue, hb_queue]: | |||
clear_queue(q) | |||
logger.info("推流进程停止完成!requestId:{}", request_id) |
@@ -10,7 +10,7 @@ service: | |||
# 图片相似度过滤 | |||
picture_similarity: true | |||
similarity: 0.65 | |||
frame_step: 300 | |||
frame_step: 160 | |||
timeout: 21600 | |||
cv2_pull_stream_timeout: 1000 | |||
cv2_read_stream_timeout: 1000 |
@@ -10,7 +10,7 @@ service: | |||
# 图片相似度过滤 | |||
picture_similarity: true | |||
similarity: 0.65 | |||
frame_step: 300 | |||
frame_step: 160 | |||
timeout: 21600 | |||
cv2_pull_stream_timeout: 1000 | |||
cv2_read_stream_timeout: 1000 |
@@ -10,7 +10,7 @@ service: | |||
# 图片相似度过滤 | |||
picture_similarity: true | |||
similarity: 0.65 | |||
frame_step: 300 | |||
frame_step: 160 | |||
timeout: 21600 | |||
cv2_pull_stream_timeout: 1000 | |||
cv2_read_stream_timeout: 1000 |
@@ -911,6 +911,7 @@ def push_video_stream(frame, push_p, push_url, p_push_status, requestId): | |||
:param requestId: 请求id | |||
:return: 推流管道 | |||
""" | |||
st = time() | |||
try: | |||
if push_p is None: | |||
height, width = frame.shape[0:2] | |||
@@ -921,6 +922,12 @@ def push_video_stream(frame, push_p, push_url, p_push_status, requestId): | |||
clear_push_p(push_p, requestId) | |||
raise s | |||
except Exception: | |||
et = time() - st | |||
logger.error("推流异常使用时间:{}, requestId: {}", et, requestId) | |||
if et > 20: | |||
logger.error("推流进管道异常:{}, requestId: {}", format_exc(), requestId) | |||
raise ServiceException(ExceptionType.PUSH_STREAMING_CHANNEL_IS_OCCUPIED.value[0], | |||
ExceptionType.PUSH_STREAMING_CHANNEL_IS_OCCUPIED.value[1]) | |||
if p_push_status[0] == 0: | |||
p_push_status[0] = time() | |||
p_push_status[1] += 1 | |||
@@ -932,7 +939,7 @@ def push_video_stream(frame, push_p, push_url, p_push_status, requestId): | |||
p_push_status[0] = time() | |||
logger.error("推流管道异常:{}, requestId: {}", format_exc(), requestId) | |||
clear_push_p(push_p, requestId) | |||
if p_push_status[1] > 150: | |||
if p_push_status[1] > 5: | |||
logger.error("推流进管道异常:{}, requestId: {}", format_exc(), requestId) | |||
raise ServiceException(ExceptionType.PUSH_STREAMING_CHANNEL_IS_OCCUPIED.value[0], | |||
ExceptionType.PUSH_STREAMING_CHANNEL_IS_OCCUPIED.value[1]) |