docs updated
parent
37918b6e23
commit
4062101616
18
README.md
18
README.md
|
@ -133,13 +133,25 @@ Place these files in the "**models**" folder.
|
|||
|
||||
We highly recommend using a `venv` to avoid issues.
|
||||
|
||||
|
||||
For Windows:
|
||||
```bash
|
||||
python -m venv venv
|
||||
venv\Scripts\activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
s
|
||||
### **PowerShell Script:**
|
||||
install_packages.ps1
|
||||
|
||||
### **Instructions:**
|
||||
1. Open PowerShell and run:
|
||||
```powershell
|
||||
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
|
||||
```
|
||||
2. Navigate to the script's location and run:
|
||||
```powershell
|
||||
.\install_packages.ps1
|
||||
|
||||
|
||||
|
||||
For Linux:
|
||||
```bash
|
||||
# Ensure you use the installed Python 3.10
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
Yes, you can share your camera with Google Colab, but since Colab runs in the cloud, it doesn't have direct access to your local webcam. However, there are workarounds:
|
||||
|
||||
### **1. Using JavaScript to Access Webcam in Colab**
|
||||
Colab provides a way to capture images using JavaScript:
|
||||
```python
|
||||
from IPython.display import display, Javascript
|
||||
from google.colab.output import eval_js
|
||||
from base64 import b64decode
|
||||
|
||||
def take_photo(filename='photo.jpg', quality=0.8):
|
||||
js = Javascript('''
|
||||
async function takePhoto(quality) {
|
||||
const div = document.createElement('div');
|
||||
const capture = document.createElement('button');
|
||||
capture.textContent = 'Capture';
|
||||
div.appendChild(capture);
|
||||
const video = document.createElement('video');
|
||||
video.style.display = 'block';
|
||||
const stream = await navigator.mediaDevices.getUserMedia({video: true});
|
||||
document.body.appendChild(div);
|
||||
div.appendChild(video);
|
||||
video.srcObject = stream;
|
||||
await video.play();
|
||||
await new Promise((resolve) => capture.onclick = resolve);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = video.videoWidth;
|
||||
canvas.height = video.videoHeight;
|
||||
canvas.getContext('2d').drawImage(video, 0, 0);
|
||||
stream.getVideoTracks()[0].stop();
|
||||
div.remove();
|
||||
return canvas.toDataURL('image/jpeg', quality);
|
||||
}
|
||||
''')
|
||||
display(js)
|
||||
data = eval_js('takePhoto({})'.format(quality))
|
||||
binary = b64decode(data.split(',')[1])
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(binary)
|
||||
return filename
|
||||
```
|
||||
This allows you to capture images from your webcam and process them in Colab.
|
||||
|
||||
### **2. Using Virtual Camera in Python**
|
||||
Python has virtual camera solutions that can simulate a webcam using images or videos:
|
||||
- **`pyvirtualcam`**: Allows you to create a virtual webcam from images or videos.
|
||||
```python
|
||||
import pyvirtualcam
|
||||
import numpy as np
|
||||
|
||||
with pyvirtualcam.Camera(width=640, height=480, fps=30) as cam:
|
||||
frame = np.zeros((480, 640, 3), dtype=np.uint8) # Black frame
|
||||
cam.send(frame)
|
||||
```
|
||||
- **`opencv`**: You can load images or videos and process them as if they were coming from a webcam.
|
||||
```python
|
||||
import cv2
|
||||
|
||||
cap = cv2.VideoCapture('your_video.mp4') # Load video as webcam
|
||||
while cap.isOpened():
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
cv2.imshow('Virtual Camera', frame)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
```
|
||||
|
||||
### **3. Running a Virtual Camera from JPG/GIF/MP3**
|
||||
- **JPG/GIF**: You can load images and display them as a webcam feed using OpenCV.
|
||||
- **MP3**: If you want to simulate audio input, you can use `pyaudio` or `sounddevice` to play an MP3 file as a virtual microphone.
|
||||
|
||||
INspired by [this Stack Overflow thread](https://stackoverflow.com/questions/54389727/opening-web-camera-in-google-colab) and [this GitHub repo](https://github.com/theAIGuysCode/colab-webcam).
|
|
@ -0,0 +1,15 @@
|
|||
For Windows, you can achieve the same functionality using PowerShell or a batch script. Here's a PowerShell script that downloads packages using `wget` (or `Invoke-WebRequest` if `wget` isn't available), caches them, and then installs from the cache:
|
||||
|
||||
### **PowerShell Script:**
|
||||
|
||||
### **Instructions:**
|
||||
1. Open PowerShell and run:
|
||||
```powershell
|
||||
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
|
||||
```
|
||||
2. Navigate to the script's location and run:
|
||||
```powershell
|
||||
.\install_packages.ps1
|
||||
```
|
||||
|
||||
This setup ensures downloads can be resumed and cached, avoiding unnecessary re-downloads.
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
# Define a local cache directory
|
||||
CACHE_DIR="$HOME/pip_cache"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
# List of packages and their URLs
|
||||
PACKAGES=(
|
||||
"https://download.pytorch.org/whl/cu118/torch-2.5.1%2Bcu118-cp38-cp38-linux_x86_64.whl"
|
||||
"https://download.pytorch.org/whl/cu118/torchvision-0.20.1-cp38-cp38-linux_x86_64.whl"
|
||||
"https://files.pythonhosted.org/packages/.../numpy-1.23.5.whl"
|
||||
"https://files.pythonhosted.org/packages/.../onnx-1.16.0.whl"
|
||||
# Add other package links here
|
||||
)
|
||||
|
||||
# Download packages with resume support
|
||||
for url in "${PACKAGES[@]}"; do
|
||||
wget -c "$url" -P "$CACHE_DIR"
|
||||
done
|
||||
|
||||
# Install packages from the cache
|
||||
pip install --find-links="$CACHE_DIR" numpy typing-extensions opencv-python \
|
||||
cv2_enumerate_cameras onnx insightface psutil tk customtkinter pillow \
|
||||
torch torchvision onnxruntime-gpu tensorflow opennsfw2 protobuf
|
|
@ -0,0 +1,34 @@
|
|||
# Define a local cache directory
|
||||
$CacheDir = "$HOME\pip_cache"
|
||||
if (!(Test-Path $CacheDir)) { New-Item -ItemType Directory -Path $CacheDir }
|
||||
|
||||
# List of package URLs
|
||||
$Packages = @(
|
||||
"https://download.pytorch.org/whl/cu118/torch-2.5.1%2Bcu118-cp38-cp38-win_amd64.whl"
|
||||
"https://download.pytorch.org/whl/cu118/torchvision-0.20.1-cp38-cp38-win_amd64.whl"
|
||||
"https://files.pythonhosted.org/packages/.../numpy-1.23.5.whl"
|
||||
"https://files.pythonhosted.org/packages/.../onnx-1.16.0.whl"
|
||||
# Add other package URLs here
|
||||
)
|
||||
|
||||
# Function to download using wget or Invoke-WebRequest
|
||||
Function Download-Package {
|
||||
param([string]$url, [string]$dest)
|
||||
if (Get-Command wget -ErrorAction SilentlyContinue) {
|
||||
wget -c $url -O $dest
|
||||
} else {
|
||||
Invoke-WebRequest -Uri $url -OutFile $dest
|
||||
}
|
||||
}
|
||||
|
||||
# Download packages with resume support
|
||||
foreach ($url in $Packages) {
|
||||
$FileName = Split-Path -Path $url -Leaf
|
||||
$DestPath = "$CacheDir\$FileName"
|
||||
Download-Package -url $url -dest $DestPath
|
||||
}
|
||||
|
||||
# Install packages from the cache
|
||||
pip install --find-links="$CacheDir" numpy typing-extensions opencv-python `
|
||||
cv2_enumerate_cameras onnx insightface psutil tk customtkinter pillow `
|
||||
torch torchvision onnxruntime-gpu tensorflow opennsfw2 protobuf
|
Loading…
Reference in New Issue