-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
162 lines (131 loc) · 4.71 KB
/
Copy pathmain.py
File metadata and controls
162 lines (131 loc) · 4.71 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
#!/usr/bin/env python3
"""
WhatsApp Custom Virtual Background
Main entry point for the virtual background system
Usage:
python main.py --mode preview --bg your_room.png
python main.py --mode virtualcam --bg your_room.glb
python main.py --test
"""
import argparse
import sys
import os
from pathlib import Path
# Ensure imports work
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from config import VirtualBGConfig, CONFIG_DEFAULT, CONFIG_HIGH_QUALITY, CONFIG_LOW_LATENCY, CONFIG_MOBILE
def run_preview(args):
"""Run in preview mode with GUI"""
from virtual_camera import WhatsAppVirtualCamera
print("=" * 50)
print("WhatsApp Virtual Background - Preview Mode")
print("=" * 50)
config = CONFIG_DEFAULT
if args.quality == "high":
config = CONFIG_HIGH_QUALITY
elif args.quality == "low":
config = CONFIG_LOW_LATENCY
elif args.quality == "mobile":
config = CONFIG_MOBILE
# Override with command line args
if args.width:
config.width = args.width
if args.height:
config.height = args.height
if args.fps:
config.fps = args.fps
# Get background path
bg_path = args.bg if args.bg else None
bg_3d_path = args.bg_3d if args.bg_3d else None
if not bg_path and not bg_3d_path:
print("\nWarning: No background specified. Using default gradient.")
print("To use your Polycam scan, provide the path with --bg or --bg-3d")
print(f"\nSettings:")
print(f" Resolution: {config.width}x{config.height}")
print(f" FPS: {config.fps}")
print(f" Background: {bg_path or bg_3d_path or 'Default'}")
print(f" Quality: {args.quality}")
print()
try:
vcam = WhatsAppVirtualCamera(
bg_path=bg_path,
bg_3d_path=bg_3d_path,
width=config.width,
height=config.height,
fps=config.fps
)
vcam.start(webcam_index=args.camera)
except KeyboardInterrupt:
print("\nInterrupted by user")
except Exception as e:
print(f"\nError: {e}")
import traceback
traceback.print_exc()
def run_virtualcam(args):
"""Run as virtual camera source"""
from virtual_camera import WhatsAppVirtualCamera
print("=" * 50)
print("WhatsApp Virtual Background - Virtual Camera Mode")
print("=" * 50)
print("\nThis will create a virtual camera device.")
print("Select it in WhatsApp > Settings > Camera")
print("Press Ctrl+C to stop\n")
config = CONFIG_DEFAULT
bg_path = args.bg if args.bg else None
bg_3d_path = args.bg_3d if args.bg_3d else None
try:
vcam = WhatsAppVirtualCamera(
bg_path=bg_path,
bg_3d_path=bg_3d_path,
width=config.width,
height=config.height,
fps=config.fps
)
vcam.start(webcam_index=args.camera)
except Exception as e:
print(f"Error: {e}")
def run_test(args):
"""Run test suite"""
from virtual_camera import test_virtual_camera
test_virtual_camera()
def main():
parser = argparse.ArgumentParser(
description='WhatsApp Custom Virtual Background',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s --mode preview --bg my_room.jpg
%(prog)s --mode virtualcam --bg-3d room_scan.glb
%(prog)s --test
%(prog)s --mode preview --quality high --bg background.png
"""
)
# Main arguments
parser.add_argument('--mode', type=str, default='preview',
choices=['preview', 'virtualcam', 'test'],
help='Operation mode (default: preview)')
# Background options
parser.add_argument('--bg', type=str, help='Path to 2D background image')
parser.add_argument('--bg-3d', type=str, help='Path to 3D scene file (GLB/GLTF/OBJ)')
# Camera options
parser.add_argument('--camera', type=int, default=0, help='Webcam index (default: 0)')
parser.add_argument('--width', type=int, help='Output width')
parser.add_argument('--height', type=int, help='Output height')
parser.add_argument('--fps', type=int, help='Frame rate')
# Quality settings
parser.add_argument('--quality', type=str, default='default',
choices=['default', 'high', 'low', 'mobile'],
help='Quality preset (default: default)')
# Test mode
parser.add_argument('--test', action='store_true', help='Run test mode')
args = parser.parse_args()
if args.test or args.mode == 'test':
run_test(args)
elif args.mode == 'preview':
run_preview(args)
elif args.mode == 'virtualcam':
run_virtualcam(args)
else:
parser.print_help()
if __name__ == "__main__":
main()