-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_camera_complete.py
More file actions
239 lines (201 loc) Β· 8.83 KB
/
Copy pathvirtual_camera_complete.py
File metadata and controls
239 lines (201 loc) Β· 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
"""
BlurBerry Complete Virtual Camera Script
This script:
1. Runs camera with face enrollment
2. Starts virtual camera with privacy protection
3. Blocks: License plates, Credit cards, NSFW content, Text PII
4. Whitelists enrolled faces (your face stays clear)
5. Streams to Zoom/Discord via OBS Virtual Camera
"""
import cv2
import numpy as np
import sys
import time
import os
from datetime import datetime
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from shared_types import PipelineConfig
from blurberry.video.virtual_video_loop import VirtualVideoLoop
from blurberry.video.face_pipeline import FacePipeline
from blurberry.video.object_detector import PlateCardDetector
# Virtual camera import
try:
import pyvirtualcam
VIRTUAL_CAMERA_AVAILABLE = True
print("β
Virtual camera available")
except ImportError:
VIRTUAL_CAMERA_AVAILABLE = False
print("β οΈ Virtual camera not available, using local display")
FRAMES_NEEDED = 60 # collect 60 frames for enrollment
def complete_virtual_camera():
"""Complete virtual camera with face enrollment and privacy protection"""
print("\n" + "="*60)
print("π BlurBerry AI - Complete Virtual Camera")
print("="*60)
print("\nπ Privacy Protection Features:")
print(" β
Face Recognition (your face stays clear)")
print(" β License Plates (auto-blurred)")
print(" β Credit Cards (auto-blurred)")
print(" β NSFW Content (auto-blurred)")
print(" β Text PII (auto-blurred)")
print("\nπ Controls:")
print(" E - Enroll your face")
print(" S - Skip enrollment, start virtual camera")
print(" Q - Quit")
print("\nπ₯ Output: OBS Virtual Camera (for Zoom/Discord)")
print("="*60)
# Configuration with all privacy features enabled
config = PipelineConfig(
blur_faces=True, # Enable face blur (whitelisted faces won't be blurred)
blur_plates=True, # Blur license plates
blur_cards=True, # Blur credit cards
blur_nsfw=True, # Blur NSFW content
blur_text_pii=True, # Blur text PII
detection_cadence=10, # Run object detection every 10 frames
blur_strength=51, # Gaussian blur kernel size
face_similarity_threshold=0.38 # Face recognition threshold
)
# Initialize face pipeline
face_pipeline = FacePipeline(config)
# Setup camera for enrollment
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
collecting = False
embeddings_collected = []
enrolled = False
# Enrollment phase
while True:
ret, frame = cap.read()
if not ret:
break
display = frame.copy()
faces = face_pipeline.face_app.get(frame)
if collecting:
if faces:
face = max(faces, key=lambda f: (f.bbox[2]-f.bbox[0]) * (f.bbox[3]-f.bbox[1]))
embeddings_collected.append(face.embedding)
# Draw progress bar
progress = len(embeddings_collected) / FRAMES_NEEDED
bar_w = int(400 * progress)
cv2.rectangle(display, (120, 680), (520, 700), (50, 50, 50), -1)
cv2.rectangle(display, (120, 680), (120 + bar_w, 700), (0, 220, 100), -1)
cv2.putText(display, f"Enrolling: {len(embeddings_collected)}/{FRAMES_NEEDED}",
(120, 675), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 220, 100), 2)
# Draw box around face being enrolled
x1, y1, x2, y2 = [int(v) for v in face.bbox]
cv2.rectangle(display, (x1, y1), (x2, y2), (0, 220, 100), 2)
cv2.putText(display, "Enrolling...", (x1, y1 - 8),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 220, 100), 2)
else:
cv2.putText(display, "No face detected β look at camera",
(120, 450), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 100, 255), 2)
# Auto-finish when enough frames collected
if len(embeddings_collected) >= FRAMES_NEEDED:
collecting = False
face_pipeline.enroll_from_embeddings(embeddings_collected, name="owner")
enrolled = True
print(f"\nβ
[Enrollment] Done! Collected {len(embeddings_collected)} frames.")
print("π― Your face is now whitelisted and will stay clear!")
else:
# Draw face boxes while idle
for face in faces:
x1, y1, x2, y2 = [int(v) for v in face.bbox]
cv2.rectangle(display, (x1, y1), (x2, y2), (200, 200, 200), 1)
# Status overlay
status = ""
if enrolled:
status = "β
Face enrolled! Press S to start virtual camera"
color = (0, 220, 100)
elif collecting:
status = "πΈ Collecting frames..."
color = (0, 200, 255)
else:
status = "Press E to enroll your face | Press S to skip enrollment"
color = (200, 200, 200)
cv2.putText(display, status, (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.55, color, 2)
# Privacy features status
privacy_status = "π Privacy: Plates, Cards, NSFW, PII will be blurred"
cv2.putText(display, privacy_status, (10, 60),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 165, 0), 2)
# Virtual camera status
if VIRTUAL_CAMERA_AVAILABLE:
cv2.putText(display, "π₯ Virtual Camera Ready", (10, 90),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
# Instructions
cv2.putText(display, "E: Enroll | S: Start Camera | Q: Quit", (10, 720-20),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
cv2.imshow("BlurBerry β Complete Virtual Camera Setup", display)
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
cap.release()
cv2.destroyAllWindows()
sys.exit(0)
elif key == ord('e') and not collecting:
embeddings_collected = []
collecting = True
print("\nπΈ [Enrollment] Started collecting frames. Hold still and face the camera.")
print("π― Your face will be whitelisted and stay clear in virtual camera!")
elif key == ord('s'):
cap.release()
cv2.destroyAllWindows()
break
# ββ Start Complete Virtual Camera Streaming ββ
print("\n" + "="*60)
print("π Starting Complete Virtual Camera...")
print("="*60)
if enrolled:
print("β
Your enrolled face will NOT be blurred.")
print("π― All other faces WILL be blurred.")
else:
print("β οΈ No face enrolled. ALL detected faces will be blurred.")
print("\nπ Privacy Protection Active:")
print(" β License Plates - Blurred")
print(" β Credit Cards - Blurred")
print(" β NSFW Content - Blurred")
print(" β Text PII - Blurred")
print(" β
Your Face - Clear (if enrolled)")
print("\nπ₯ Virtual Camera: OBS Virtual Camera")
print("π± Compatible: Zoom, Discord, Teams, Meet")
print("βΉοΈ Press Q to quit")
print("="*60)
# Create virtual video loop
loop = VirtualVideoLoop(config, source=0, debug=False)
# Pass the already-enrolled face pipeline into the loop
loop.face_pipeline = face_pipeline
# Add object detector for privacy features
object_detector = PlateCardDetector()
loop.add_detector(object_detector.detect)
print("π Object detectors loaded:")
print(" - License plates (will be blurred)")
print(" - Credit cards (will be blurred)")
print(" - NSFW content (will be blurred)")
print(" - Text PII (will be blurred)")
try:
# Start virtual camera stream with all privacy features
loop.run(use_virtual_camera=True)
except KeyboardInterrupt:
print("\nπ Stopped by user")
except Exception as e:
print(f"β Error: {e}")
print("π‘ Make sure OBS Studio is installed for virtual camera")
finally:
loop.stop()
print("\nπ Virtual camera stream stopped")
print("π― Privacy protection disabled")
print("="*60)
if __name__ == "__main__":
print("π BlurBerry AI - Complete Privacy Virtual Camera")
print("="*60)
# Check virtual camera availability
if not VIRTUAL_CAMERA_AVAILABLE:
print("β οΈ Warning: Virtual camera not available")
print(" Install with: pip install pyvirtualcam")
print(" Or install OBS Studio for virtual camera driver")
response = input("Continue with local display? (y/n): ").strip().lower()
if response != 'y':
sys.exit(0)
# Run complete virtual camera
complete_virtual_camera()