ocr1.0
This commit is contained in:
21
rtc/rtc.py
21
rtc/rtc.py
@ -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():
|
||||
|
Reference in New Issue
Block a user