mirror of
https://github.com/facefusion/facefusion.git
synced 2026-07-29 05:18:57 +02:00
Use is vision frame everywhere (#1210)
* use is_vision_frame everywhere * fix hash * fix lint
This commit is contained in:
@@ -9,7 +9,7 @@ from facefusion.download import conditional_download_hashes, conditional_downloa
|
||||
from facefusion.filesystem import resolve_relative_path
|
||||
from facefusion.thread_helper import conditional_thread_semaphore
|
||||
from facefusion.types import Detection, DownloadScope, DownloadSet, Fps, InferencePool, ModelSet, VisionFrame
|
||||
from facefusion.vision import detect_video_fps, fit_contain_frame, read_image
|
||||
from facefusion.vision import detect_video_fps, fit_contain_frame, is_vision_frame, read_image
|
||||
|
||||
STREAM_COUNTER = 0
|
||||
|
||||
@@ -172,7 +172,7 @@ def analyse_video(video_path : str, trim_frame_start : int, trim_frame_end : int
|
||||
vision_frame = video_manager.read_video_frame(video_reader)
|
||||
|
||||
if frame_number % int(video_fps) == 0:
|
||||
if numpy.any(vision_frame):
|
||||
if is_vision_frame(vision_frame):
|
||||
total += 1
|
||||
|
||||
if analyse_frame(vision_frame):
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ def pre_check() -> bool:
|
||||
def common_pre_check() -> bool:
|
||||
content_analyser_content = inspect.getsource(content_analyser).encode()
|
||||
|
||||
return hash_helper.create_hash(content_analyser_content) == '0922c180'
|
||||
return hash_helper.create_hash(content_analyser_content) == '3c6ce25e'
|
||||
|
||||
|
||||
def processors_pre_check() -> bool:
|
||||
|
||||
@@ -10,6 +10,7 @@ from facefusion.face_helper import apply_nms, average_points, convert_to_face_la
|
||||
from facefusion.face_landmarker import detect_face_landmark, estimate_face_landmark_68_5
|
||||
from facefusion.face_recognizer import calculate_face_embedding
|
||||
from facefusion.types import BoundingBox, Face, FaceLandmark5, FaceLandmarkSet, FaceScoreSet, Score, VisionFrame
|
||||
from facefusion.vision import is_vision_frame
|
||||
|
||||
|
||||
def create_faces(vision_frame : VisionFrame, bounding_boxes : List[BoundingBox], face_scores : List[Score], face_landmarks_5 : List[FaceLandmark5]) -> List[Face]:
|
||||
@@ -73,7 +74,7 @@ def get_many_faces(vision_frames : List[VisionFrame]) -> List[Face]:
|
||||
many_faces : List[Face] = []
|
||||
|
||||
for vision_frame in vision_frames:
|
||||
if numpy.any(vision_frame):
|
||||
if is_vision_frame(vision_frame):
|
||||
all_bounding_boxes = []
|
||||
all_face_scores = []
|
||||
all_face_landmarks_5 = []
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import threading
|
||||
from typing import List, Optional
|
||||
|
||||
import numpy
|
||||
|
||||
from facefusion.hash_helper import create_hash
|
||||
from facefusion.types import Face, FaceStore, VisionFrame
|
||||
from facefusion.vision import is_vision_frame
|
||||
|
||||
FACE_STORE : FaceStore = {}
|
||||
|
||||
|
||||
def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
||||
if numpy.any(vision_frame):
|
||||
if is_vision_frame(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.data)
|
||||
|
||||
if FACE_STORE.get(vision_hash):
|
||||
@@ -20,7 +19,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):
|
||||
if is_vision_frame(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.data)
|
||||
FACE_STORE.setdefault(vision_hash,
|
||||
{
|
||||
@@ -29,7 +28,7 @@ def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
||||
|
||||
|
||||
def resolve_lock(vision_frame : VisionFrame) -> threading.Lock:
|
||||
if numpy.any(vision_frame):
|
||||
if is_vision_frame(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.data)
|
||||
return FACE_STORE.setdefault(vision_hash,
|
||||
{
|
||||
|
||||
@@ -5,7 +5,6 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Deque, Iterator, List
|
||||
|
||||
import cv2
|
||||
import numpy
|
||||
from tqdm import tqdm
|
||||
|
||||
from facefusion import ffmpeg_builder, logger, state_manager, translator
|
||||
@@ -15,7 +14,7 @@ from facefusion.ffmpeg import open_ffmpeg
|
||||
from facefusion.filesystem import is_directory
|
||||
from facefusion.processors.core import get_processors_modules
|
||||
from facefusion.types import Fps, StreamMode, VisionFrame
|
||||
from facefusion.vision import extract_vision_mask, read_static_images
|
||||
from facefusion.vision import extract_vision_mask, is_vision_frame, read_static_images
|
||||
|
||||
|
||||
def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) -> Iterator[VisionFrame]:
|
||||
@@ -31,7 +30,7 @@ def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) -
|
||||
if analyse_stream(capture_vision_frame, camera_fps):
|
||||
camera_capture.release()
|
||||
|
||||
if numpy.any(capture_vision_frame):
|
||||
if is_vision_frame(capture_vision_frame):
|
||||
future = executor.submit(process_stream_frame, source_vision_frames, capture_vision_frame)
|
||||
futures.append(future)
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from facefusion.types import AudioFrame, Face, Mask, VisionFrame
|
||||
from facefusion.uis import choices as uis_choices
|
||||
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
||||
from facefusion.uis.types import ComponentOptions, PreviewMode
|
||||
from facefusion.vision import detect_frame_orientation, extract_vision_mask, fit_cover_frame, merge_vision_mask, obscure_frame, read_static_image, read_static_images, read_video_frame, restrict_frame, select_video_frames, unpack_resolution
|
||||
from facefusion.vision import detect_frame_orientation, extract_vision_mask, fit_cover_frame, is_vision_frame, merge_vision_mask, obscure_frame, read_static_image, read_static_images, read_video_frame, restrict_frame, select_video_frames, unpack_resolution
|
||||
|
||||
PREVIEW_IMAGE : Optional[gradio.Image] = None
|
||||
|
||||
@@ -277,7 +277,7 @@ def create_face_by_face(reference_vision_frame : VisionFrame, source_vision_fram
|
||||
target_crop_vision_frame = extract_crop_frame(target_vision_frame, target_face)
|
||||
output_crop_vision_frame = extract_crop_frame(temp_vision_frame, target_face)
|
||||
|
||||
if numpy.any(target_crop_vision_frame) and numpy.any(output_crop_vision_frame):
|
||||
if is_vision_frame(target_crop_vision_frame) and is_vision_frame(output_crop_vision_frame):
|
||||
target_crop_dimension = min(target_crop_vision_frame.shape[:2])
|
||||
target_crop_vision_frame = fit_cover_frame(target_crop_vision_frame, (target_crop_dimension, target_crop_dimension))
|
||||
output_crop_vision_frame = fit_cover_frame(output_crop_vision_frame, (target_crop_dimension, target_crop_dimension))
|
||||
|
||||
Reference in New Issue
Block a user