This commit is contained in:
2025-09-02 21:30:28 +08:00
parent df74b688fa
commit e21432c6a1
4 changed files with 219 additions and 62 deletions

View File

@ -4,6 +4,7 @@ import cv2 # 导入OpenCV库
import numpy as np
from aiortc import RTCPeerConnection, RTCSessionDescription, RTCConfiguration
from aiortc.mediastreams import MediaStreamTrack
from ocr.ocr_violation_detector import OCRViolationDetector
class VideoTrack(MediaStreamTrack):
@ -47,7 +48,7 @@ async def rtc_frame_receiver(url, frame_queue):
if frame_queue.empty():
# 队列为空、放入当前cv2帧
await frame_queue.put(frame_cv2)
print(f"{total_frames}队列为空、已放入新的cv2帧尺寸: {frame_cv2.shape}")
# print(f"第{total_frames}队列为空、已放入新的cv2帧尺寸: {frame_cv2.shape}")
else:
# 队列非空、说明上一帧还未处理、跳过当前帧
print(f"{total_frames}帧:队列非空、跳过该帧")
@ -93,23 +94,35 @@ async def frame_consumer(frame_queue):
Args: frame_queue: 帧队列
"""
# 创建OCR检测器实例请替换为实际的违禁词文件路径
ocr_detector = OCRViolationDetector(
forbidden_words_path=r"D:\Git\bin\video\ocr\forbidden_words.txt", # 替换为实际路径
ocr_confidence_threshold=0.5,)
while True:
# 从队列中获取cv2帧队列为空时会阻塞等待新帧
current_frame = await frame_queue.get()
ocr_detector.detect(current_frame)
# 验证这是cv2可以处理的帧
print(f"从队列获取到cv2帧、尺寸: {current_frame.shape}、数据类型: {current_frame.dtype}")
# print(f"从队列获取到cv2帧、尺寸: {current_frame.shape}、数据类型: {current_frame.dtype}")
# 这里可以添加cv2的处理代码例如显示帧
# cv2.imshow('Received Frame', current_frame)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
print("cv2帧处理完成")
# print("cv2帧处理完成")
# 标记任务完成
frame_queue.task_done()
print("帧处理完成、队列已清空")
# print("帧处理完成、队列已清空")
async def main():