avoid tobytes copy (#1208)

This commit is contained in:
Henry Ruhs
2026-07-28 10:02:08 +02:00
committed by GitHub
parent 5e8a37110d
commit a394d48f34
3 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ FACE_STORE : FaceStore = {}
def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
if numpy.any(vision_frame):
vision_hash = create_hash(vision_frame.tobytes())
vision_hash = create_hash(vision_frame.data)
if FACE_STORE.get(vision_hash):
return FACE_STORE.get(vision_hash).get('faces')
@@ -21,7 +21,7 @@ def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
if numpy.any(vision_frame):
vision_hash = create_hash(vision_frame.tobytes())
vision_hash = create_hash(vision_frame.data)
FACE_STORE.setdefault(vision_hash,
{
'lock': threading.Lock()
@@ -30,7 +30,7 @@ def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
def resolve_lock(vision_frame : VisionFrame) -> threading.Lock:
if numpy.any(vision_frame):
vision_hash = create_hash(vision_frame.tobytes())
vision_hash = create_hash(vision_frame.data)
return FACE_STORE.setdefault(vision_hash,
{
'lock': threading.Lock()
+1 -1
View File
@@ -106,7 +106,7 @@ def start(webcam_device_id : int, webcam_mode : WebcamMode, webcam_resolution :
yield capture_vision_frame
if webcam_mode in [ 'udp', 'v4l2' ]:
try:
stream.stdin.write(capture_vision_frame.tobytes())
stream.stdin.write(capture_vision_frame.data)
except Exception:
pass
+1 -1
View File
@@ -133,7 +133,7 @@ def get_writer(video_path : str, temp_video_fps : Fps, temp_video_resolution : R
def write_video_frame(video_writer : VideoWriter, vision_frame : VisionFrame) -> None:
video_writer.get('process').stdin.write(vision_frame.tobytes())
video_writer.get('process').stdin.write(vision_frame.data)
def close_video_writer(video_writer : VideoWriter) -> bool: