视频检索返回结果增加更多信息

This commit is contained in:
zqc
2025-12-21 12:50:31 +08:00
parent 93f7e11f9e
commit d1509fccc9

View File

@@ -256,7 +256,7 @@ class VideoCheckBiz(BaseFaceBiz):
return None
def batch_process_videos_with_blacklist_detection(self, video_paths: List[str], frame_skip: int = 10,
suffix: str = "_processed") -> List[str]:
suffix: str = "_processed") -> List[Dict]:
"""
批量处理视频文件,进行黑名单检测并保存结果
@@ -266,9 +266,17 @@ class VideoCheckBiz(BaseFaceBiz):
suffix: 输出文件后缀
返回:
处理后的视频路径列表
处理结果列表,每个元素包含:
{
'original_path': 原视频路径,
'processed_path': 处理后的视频路径,
'has_blacklist_match': 是否检测到黑名单中人脸,
'detection_count': 黑名单匹配次数,
'total_frames_processed': 处理的总帧数,
'blacklist_matches': 黑名单匹配详情列表
}
"""
processed_paths = []
results = []
# 确保使用黑名单模式
self.set_list_mode("blacklist")
@@ -281,21 +289,47 @@ class VideoCheckBiz(BaseFaceBiz):
if not os.path.exists(video_path):
print(f"❌ 视频文件不存在: {video_path}")
results.append({
'original_path': video_path,
'processed_path': None,
'has_blacklist_match': False,
'detection_count': 0,
'total_frames_processed': 0,
'blacklist_matches': [],
'error': '文件不存在'
})
continue
# 处理单个视频
output_path = self._process_single_video_with_detection(video_path, frame_skip, suffix)
result = self._process_single_video_with_detection(video_path, frame_skip, suffix)
if output_path:
processed_paths.append(output_path)
print(f"✅ 视频处理完成: {os.path.basename(output_path)}")
if result and result['processed_path']:
results.append(result)
status = "✅ 检测到黑名单" if result['has_blacklist_match'] else "⚠️ 未检测到黑名单"
print(f"{status}: {os.path.basename(result['processed_path'])} (匹配次数: {result['detection_count']})")
else:
error_result = {
'original_path': video_path,
'processed_path': None,
'has_blacklist_match': False,
'detection_count': 0,
'total_frames_processed': 0,
'blacklist_matches': [],
'error': '处理失败'
}
results.append(error_result)
print(f"❌ 视频处理失败: {os.path.basename(video_path)}")
print(f"\n🎉 批量处理完成: 成功{len(processed_paths)}/{len(video_paths)}个视频")
return processed_paths
# 统计结果
success_count = sum(1 for r in results if r.get('processed_path'))
blacklist_count = sum(1 for r in results if r.get('has_blacklist_match'))
print(f"\n🎉 批量处理完成: 成功{success_count}/{len(video_paths)}个视频")
print(f"🔍 黑名单检测结果: {blacklist_count}个视频检测到黑名单中人脸")
return results
def _process_single_video_with_detection(self, video_path: str, frame_skip: int, suffix: str) -> Optional[str]:
def _process_single_video_with_detection(self, video_path: str, frame_skip: int, suffix: str) -> Optional[Dict]:
"""
处理单个视频,进行黑名单检测并保存结果
@@ -305,7 +339,15 @@ class VideoCheckBiz(BaseFaceBiz):
suffix: 输出文件后缀
返回:
处理后的视频路径
处理结果字典,包含:
{
'original_path': 原视频路径,
'processed_path': 处理后的视频路径,
'has_blacklist_match': 是否检测到黑名单中人脸,
'detection_count': 黑名单匹配次数,
'total_frames_processed': 处理的总帧数,
'blacklist_matches': 黑名单匹配详情列表
}
"""
# 打开输入视频
cap = cv2.VideoCapture(video_path)
@@ -394,7 +436,20 @@ class VideoCheckBiz(BaseFaceBiz):
print(f"📊 处理统计: 处理{processed_frames}帧, 检测到{detection_count}次黑名单匹配")
return output_path
# 返回详细结果
return {
'original_path': video_path,
'processed_path': output_path,
'has_blacklist_match': detection_count > 0,
'detection_count': detection_count,
'total_frames_processed': processed_frames,
'blacklist_matches': [{
'frame_index': frame_index,
'best_match': result['best_match'],
'similarity': result['similarity'],
'bbox': result['bbox']
} for result in results if result['is_match']]
}
def process_video_with_custom_detection(self, video_path: str, frame_skip: int = 10,
suffix: str = "_detected",