-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
211 lines (169 loc) · 5.82 KB
/
setup.py
File metadata and controls
211 lines (169 loc) · 5.82 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
#!/usr/bin/env python3
"""
Setup script for Lockless Biometric Authentication System.
This script helps set up the development environment and dependencies.
"""
import os
import sys
import subprocess
import platform
from pathlib import Path
def run_command(command, description="", check=True):
"""Run a command and handle errors."""
print(f"Running: {description or command}")
try:
result = subprocess.run(command, shell=True, check=check,
capture_output=True, text=True)
if result.stdout:
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
if e.stderr:
print(f"Error output: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible."""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("Error: Python 3.8 or higher is required")
print(
f"Current version: {version.major}.{version.minor}.{version.micro}")
return False
print(
f"✓ Python version {version.major}.{version.minor}.{version.micro} is compatible")
return True
def create_virtual_environment():
"""Create a virtual environment."""
if os.path.exists(".venv"):
print("✓ Virtual environment already exists")
return True
print("Creating virtual environment...")
return run_command("python -m venv .venv", "Creating virtual environment")
def activate_venv_command():
"""Get the command to activate virtual environment."""
if platform.system() == "Windows":
return ".venv\\Scripts\\activate"
else:
return "source .venv/bin/activate"
def install_dependencies():
"""Install Python dependencies."""
# Determine pip command based on platform
if platform.system() == "Windows":
pip_cmd = ".venv\\Scripts\\pip"
python_cmd = ".venv\\Scripts\\python"
else:
pip_cmd = ".venv/bin/pip"
python_cmd = ".venv/bin/python"
print("Installing dependencies...")
# Upgrade pip first
if not run_command(f"{pip_cmd} install --upgrade pip", "Upgrading pip"):
return False
# Install requirements
if os.path.exists("requirements.txt"):
return run_command(f"{pip_cmd} install -r requirements.txt",
"Installing requirements.txt")
else:
# Install basic dependencies manually
basic_deps = [
"opencv-python>=4.8.0",
"numpy>=1.24.0",
"PyYAML>=6.0",
"cryptography>=41.0.0",
"Pillow>=10.0.0",
"psutil>=5.9.0"
]
for dep in basic_deps:
if not run_command(f"{pip_cmd} install {dep}", f"Installing {dep}"):
return False
return True
def setup_directories():
"""Create necessary directories."""
directories = [
"data",
"logs",
"models",
"templates",
"tests/data"
]
for dir_path in directories:
Path(dir_path).mkdir(parents=True, exist_ok=True)
print(f"✓ Created directory: {dir_path}")
return True
def check_camera():
"""Check if camera is available."""
try:
import cv2
cap = cv2.VideoCapture(0)
if cap.isOpened():
ret, frame = cap.read()
cap.release()
if ret:
print("✓ Camera is working")
return True
else:
print("⚠ Camera detected but cannot capture frames")
return False
else:
print("⚠ No camera detected or camera is busy")
return False
except ImportError:
print("⚠ OpenCV not installed, cannot test camera")
return False
except Exception as e:
print(f"⚠ Camera test failed: {e}")
return False
def create_sample_config():
"""Create a sample configuration file."""
config_content = """# Lockless Configuration
system:
log_level: "DEBUG" # Use DEBUG for development
data_directory: "./data"
camera:
device_id: 0 # Change if you have multiple cameras
authentication:
similarity_threshold: 0.6 # Lower for testing (normally 0.7)
quality_threshold: 0.5 # Lower for testing (normally 0.6)
enrollment:
required_samples: 3 # Fewer samples for testing (normally 5)
quality_threshold: 0.5
performance:
enable_gpu_acceleration: false # Set to true if you have compatible GPU
"""
with open("config/development.yaml", "w") as f:
f.write(config_content)
print("✓ Created development configuration file")
def main():
"""Main setup function."""
print("Lockless Biometric Authentication System - Setup")
print("=" * 50)
# Check Python version
if not check_python_version():
return 1
# Create virtual environment
if not create_virtual_environment():
print("Failed to create virtual environment")
return 1
# Install dependencies
if not install_dependencies():
print("Failed to install dependencies")
return 1
# Setup directories
if not setup_directories():
print("Failed to setup directories")
return 1
# Create sample config
create_sample_config()
print("\n" + "=" * 50)
print("Setup completed successfully!")
print("\nNext steps:")
print(f"1. Activate virtual environment: {activate_venv_command()}")
print("2. Test camera: python src/main.py --test-camera")
print("3. Enroll a user: python src/main.py --enroll --user test_user --password test123")
print("4. Authenticate: python src/main.py --authenticate --user test_user --password test123")
# Test camera if possible
print("\nTesting camera...")
check_camera()
return 0
if __name__ == "__main__":
sys.exit(main())