commit
47c8f7acc0
@ -1,3 +1,3 @@
|
|||||||
name = 'Deep-Live-Cam'
|
name = 'Deep-Live-Cam'
|
||||||
version = '1.7.0'
|
version = '1.7.5'
|
||||||
edition = 'Github Edition'
|
edition = 'GitHub Edition'
|
||||||
|
|||||||
@ -0,0 +1,94 @@
|
|||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
from typing import Optional, Tuple, Callable
|
||||||
|
import platform
|
||||||
|
import threading
|
||||||
|
|
||||||
|
# Only import Windows-specific library if on Windows
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
from pygrabber.dshow_graph import FilterGraph
|
||||||
|
|
||||||
|
|
||||||
|
class VideoCapturer:
|
||||||
|
def __init__(self, device_index: int):
|
||||||
|
self.device_index = device_index
|
||||||
|
self.frame_callback = None
|
||||||
|
self._current_frame = None
|
||||||
|
self._frame_ready = threading.Event()
|
||||||
|
self.is_running = False
|
||||||
|
self.cap = None
|
||||||
|
|
||||||
|
# Initialize Windows-specific components if on Windows
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
self.graph = FilterGraph()
|
||||||
|
# Verify device exists
|
||||||
|
devices = self.graph.get_input_devices()
|
||||||
|
if self.device_index >= len(devices):
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid device index {device_index}. Available devices: {len(devices)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def start(self, width: int = 960, height: int = 540, fps: int = 60) -> bool:
|
||||||
|
"""Initialize and start video capture"""
|
||||||
|
try:
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
# Windows-specific capture methods
|
||||||
|
capture_methods = [
|
||||||
|
(self.device_index, cv2.CAP_DSHOW), # Try DirectShow first
|
||||||
|
(self.device_index, cv2.CAP_ANY), # Then try default backend
|
||||||
|
(-1, cv2.CAP_ANY), # Try -1 as fallback
|
||||||
|
(0, cv2.CAP_ANY), # Finally try 0 without specific backend
|
||||||
|
]
|
||||||
|
|
||||||
|
for dev_id, backend in capture_methods:
|
||||||
|
try:
|
||||||
|
self.cap = cv2.VideoCapture(dev_id, backend)
|
||||||
|
if self.cap.isOpened():
|
||||||
|
break
|
||||||
|
self.cap.release()
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# Unix-like systems (Linux/Mac) capture method
|
||||||
|
self.cap = cv2.VideoCapture(self.device_index)
|
||||||
|
|
||||||
|
if not self.cap or not self.cap.isOpened():
|
||||||
|
raise RuntimeError("Failed to open camera")
|
||||||
|
|
||||||
|
# Configure format
|
||||||
|
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
|
||||||
|
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
||||||
|
self.cap.set(cv2.CAP_PROP_FPS, fps)
|
||||||
|
|
||||||
|
self.is_running = True
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to start capture: {str(e)}")
|
||||||
|
if self.cap:
|
||||||
|
self.cap.release()
|
||||||
|
return False
|
||||||
|
|
||||||
|
def read(self) -> Tuple[bool, Optional[np.ndarray]]:
|
||||||
|
"""Read a frame from the camera"""
|
||||||
|
if not self.is_running or self.cap is None:
|
||||||
|
return False, None
|
||||||
|
|
||||||
|
ret, frame = self.cap.read()
|
||||||
|
if ret:
|
||||||
|
self._current_frame = frame
|
||||||
|
if self.frame_callback:
|
||||||
|
self.frame_callback(frame)
|
||||||
|
return True, frame
|
||||||
|
return False, None
|
||||||
|
|
||||||
|
def release(self) -> None:
|
||||||
|
"""Stop capture and release resources"""
|
||||||
|
if self.is_running and self.cap is not None:
|
||||||
|
self.cap.release()
|
||||||
|
self.is_running = False
|
||||||
|
self.cap = None
|
||||||
|
|
||||||
|
def set_frame_callback(self, callback: Callable[[np.ndarray], None]) -> None:
|
||||||
|
"""Set callback for frame processing"""
|
||||||
|
self.frame_callback = callback
|
||||||
@ -1,122 +0,0 @@
|
|||||||
@echo off
|
|
||||||
setlocal EnableDelayedExpansion
|
|
||||||
|
|
||||||
:: 1. Setup your platform
|
|
||||||
echo Setting up your platform...
|
|
||||||
|
|
||||||
:: Python
|
|
||||||
where python >nul 2>&1
|
|
||||||
if %ERRORLEVEL% neq 0 (
|
|
||||||
echo Python is not installed. Please install Python 3.10 or later.
|
|
||||||
pause
|
|
||||||
exit /b
|
|
||||||
)
|
|
||||||
|
|
||||||
:: Pip
|
|
||||||
where pip >nul 2>&1
|
|
||||||
if %ERRORLEVEL% neq 0 (
|
|
||||||
echo Pip is not installed. Please install Pip.
|
|
||||||
pause
|
|
||||||
exit /b
|
|
||||||
)
|
|
||||||
|
|
||||||
:: Git
|
|
||||||
where git >nul 2>&1
|
|
||||||
if %ERRORLEVEL% neq 0 (
|
|
||||||
echo Git is not installed. Installing Git...
|
|
||||||
winget install --id Git.Git -e --source winget
|
|
||||||
)
|
|
||||||
|
|
||||||
:: FFMPEG
|
|
||||||
where ffmpeg >nul 2>&1
|
|
||||||
if %ERRORLEVEL% neq 0 (
|
|
||||||
echo FFMPEG is not installed. Installing FFMPEG...
|
|
||||||
winget install --id Gyan.FFmpeg -e --source winget
|
|
||||||
)
|
|
||||||
|
|
||||||
:: Visual Studio 2022 Runtimes
|
|
||||||
echo Installing Visual Studio 2022 Runtimes...
|
|
||||||
winget install --id Microsoft.VC++2015-2022Redist-x64 -e --source winget
|
|
||||||
|
|
||||||
:: 2. Clone Repository
|
|
||||||
if exist Deep-Live-Cam (
|
|
||||||
echo Deep-Live-Cam directory already exists.
|
|
||||||
set /p overwrite="Do you want to overwrite? (Y/N): "
|
|
||||||
if /i "%overwrite%"=="Y" (
|
|
||||||
rmdir /s /q Deep-Live-Cam
|
|
||||||
git clone https://github.com/hacksider/Deep-Live-Cam.git
|
|
||||||
) else (
|
|
||||||
echo Skipping clone, using existing directory.
|
|
||||||
)
|
|
||||||
) else (
|
|
||||||
git clone https://github.com/hacksider/Deep-Live-Cam.git
|
|
||||||
)
|
|
||||||
cd Deep-Live-Cam
|
|
||||||
|
|
||||||
:: 3. Download Models
|
|
||||||
echo Downloading models...
|
|
||||||
mkdir models
|
|
||||||
curl -L -o models/GFPGANv1.4.pth https://path.to.model/GFPGANv1.4.pth
|
|
||||||
curl -L -o models/inswapper_128_fp16.onnx https://path.to.model/inswapper_128_fp16.onnx
|
|
||||||
|
|
||||||
:: 4. Install dependencies
|
|
||||||
echo Creating a virtual environment...
|
|
||||||
python -m venv venv
|
|
||||||
call venv\Scripts\activate
|
|
||||||
|
|
||||||
echo Installing required Python packages...
|
|
||||||
pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
echo Setup complete. You can now run the application.
|
|
||||||
|
|
||||||
:: GPU Acceleration Options
|
|
||||||
echo.
|
|
||||||
echo Choose the GPU Acceleration Option if applicable:
|
|
||||||
echo 1. CUDA (Nvidia)
|
|
||||||
echo 2. CoreML (Apple Silicon)
|
|
||||||
echo 3. CoreML (Apple Legacy)
|
|
||||||
echo 4. DirectML (Windows)
|
|
||||||
echo 5. OpenVINO (Intel)
|
|
||||||
echo 6. None
|
|
||||||
set /p choice="Enter your choice (1-6): "
|
|
||||||
|
|
||||||
if "%choice%"=="1" (
|
|
||||||
echo Installing CUDA dependencies...
|
|
||||||
pip uninstall -y onnxruntime onnxruntime-gpu
|
|
||||||
pip install onnxruntime-gpu==1.16.3
|
|
||||||
set exec_provider="cuda"
|
|
||||||
) else if "%choice%"=="2" (
|
|
||||||
echo Installing CoreML (Apple Silicon) dependencies...
|
|
||||||
pip uninstall -y onnxruntime onnxruntime-silicon
|
|
||||||
pip install onnxruntime-silicon==1.13.1
|
|
||||||
set exec_provider="coreml"
|
|
||||||
) else if "%choice%"=="3" (
|
|
||||||
echo Installing CoreML (Apple Legacy) dependencies...
|
|
||||||
pip uninstall -y onnxruntime onnxruntime-coreml
|
|
||||||
pip install onnxruntime-coreml==1.13.1
|
|
||||||
set exec_provider="coreml"
|
|
||||||
) else if "%choice%"=="4" (
|
|
||||||
echo Installing DirectML dependencies...
|
|
||||||
pip uninstall -y onnxruntime onnxruntime-directml
|
|
||||||
pip install onnxruntime-directml==1.15.1
|
|
||||||
set exec_provider="directml"
|
|
||||||
) else if "%choice%"=="5" (
|
|
||||||
echo Installing OpenVINO dependencies...
|
|
||||||
pip uninstall -y onnxruntime onnxruntime-openvino
|
|
||||||
pip install onnxruntime-openvino==1.15.0
|
|
||||||
set exec_provider="openvino"
|
|
||||||
) else (
|
|
||||||
echo Skipping GPU acceleration setup.
|
|
||||||
)
|
|
||||||
|
|
||||||
:: Run the application
|
|
||||||
if defined exec_provider (
|
|
||||||
echo Running the application with %exec_provider% execution provider...
|
|
||||||
python run.py --execution-provider %exec_provider%
|
|
||||||
) else (
|
|
||||||
echo Running the application...
|
|
||||||
python run.py
|
|
||||||
)
|
|
||||||
|
|
||||||
pause
|
|
||||||
Loading…
Reference in new issue