-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_objects.py
More file actions
74 lines (60 loc) · 2.93 KB
/
Copy pathtest_objects.py
File metadata and controls
74 lines (60 loc) · 2.93 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
import sys
sys.path.insert(0, ".")
import cv2
from shared_types import PipelineConfig
from blurberry.video.face_pipeline import FacePipeline
from blurberry.video.object_detector import PlateCardDetector
from blurberry.video.nsfw_detector import NSFWDetector
from blurberry.video.blur_compositor import apply_blurs, draw_debug_overlay
from blurberry.video.tracker import MultiObjectTracker
config = PipelineConfig()
face_pipeline = FacePipeline(config)
plate_detector = PlateCardDetector()
nsfw_detector = NSFWDetector()
tracker = MultiObjectTracker(max_age=60, min_hits=1, iou_threshold=0.15)
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
if not cap.isOpened():
cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
frame_id = 0
last_detections = [] # plates + cards
last_nsfw_events = [] # persisted separately — NudeNet is slow
print("✅ Running. Press Q to quit.")
while True:
ret, frame = cap.read()
if not ret:
break
frame_id += 1
# ── Faces: every frame ──────────────────────────────────────────
try:
face_events = face_pipeline.detect_faces(frame, frame_id)
except Exception as e:
face_events = []
# ── Plates + Cards: every 3 frames ──────────────────────────────
if frame_id % 3 == 0:
try:
last_detections = plate_detector.detect(frame, frame_id)
if last_detections:
print(f"Frame {frame_id}: {[(e.type, round(e.confidence,2)) for e in last_detections]}")
except Exception as e:
print(f"❌ Object detect error: {e}")
# ── NSFW: every 30 frames (NudeNet is slow ~200ms) ──────────────
if frame_id % 30 == 0:
try:
last_nsfw_events = nsfw_detector.detect(frame, frame_id)
if last_nsfw_events:
print(f"Frame {frame_id}: NSFW {[(e.type, round(e.confidence,2)) for e in last_nsfw_events]}")
except Exception as e:
print(f"❌ NSFW error: {e}")
# ── Tracker: feed detections, returns smooth boxes ───────────────
# update() handles both prediction AND matching in one call
tracked = tracker.update(last_detections)
# ── Combine all events ───────────────────────────────────────────
all_events = face_events + tracked + last_nsfw_events
# ── Blur + display ───────────────────────────────────────────────
output = apply_blurs(frame, all_events, config)
output = draw_debug_overlay(output, all_events)
cv2.imshow("BlurBerry Test", output)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()