-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
190 lines (140 loc) · 4.46 KB
/
setup.py
File metadata and controls
190 lines (140 loc) · 4.46 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
"""
Setup script for ALPR system
Verifies installation and downloads required models
"""
import sys
import subprocess
import platform
from pathlib import Path
def check_python_version():
"""Check Python version"""
print("Checking Python version...")
version = sys.version_info
if version.major != 3 or version.minor < 10:
print(f"❌ Python 3.10+ required. Current: {version.major}.{version.minor}")
return False
print(f"✓ Python {version.major}.{version.minor}.{version.micro}")
return True
def check_cuda():
"""Check CUDA availability"""
print("\nChecking CUDA...")
try:
import torch
if torch.cuda.is_available():
print(f"✓ CUDA available: {torch.cuda.get_device_name(0)}")
print(f" CUDA Version: {torch.version.cuda}")
print(f" Device Count: {torch.cuda.device_count()}")
return True
else:
print("⚠ CUDA not available - will use CPU (slower)")
return False
except ImportError:
print("❌ PyTorch not installed")
return False
def check_dependencies():
"""Check if all dependencies are installed"""
print("\nChecking dependencies...")
required_packages = [
'cv2',
'torch',
'ultralytics',
'easyocr',
'yaml',
'loguru'
]
missing = []
for package in required_packages:
try:
if package == 'cv2':
import cv2
elif package == 'torch':
import torch
elif package == 'ultralytics':
import ultralytics
elif package == 'easyocr':
import easyocr
elif package == 'yaml':
import yaml
elif package == 'loguru':
import loguru
print(f"✓ {package}")
except ImportError:
print(f"❌ {package} not found")
missing.append(package)
if missing:
print(f"\n❌ Missing packages: {', '.join(missing)}")
print("Run: pip install -r requirements.txt")
return False
return True
def download_models():
"""Download required YOLO models"""
print("\nDownloading models...")
try:
from ultralytics import YOLO
# Download YOLOv8 nano model (small and fast)
print("Downloading YOLOv8n...")
model = YOLO('yolov8n.pt')
print("✓ YOLOv8n downloaded")
return True
except Exception as e:
print(f"❌ Error downloading models: {e}")
return False
def create_directories():
"""Create necessary directories"""
print("\nCreating directories...")
dirs = ['logs', 'detections', 'models']
for dir_name in dirs:
dir_path = Path(dir_name)
dir_path.mkdir(exist_ok=True)
print(f"✓ {dir_name}/")
return True
def test_camera():
"""Test camera access"""
print("\nTesting camera...")
try:
import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("⚠ Could not open default camera (index 0)")
print(" You may need to configure a different camera source")
return False
ret, frame = cap.read()
cap.release()
if ret:
print(f"✓ Camera working: {frame.shape[1]}x{frame.shape[0]}")
return True
else:
print("⚠ Camera opened but could not read frame")
return False
except Exception as e:
print(f"❌ Error testing camera: {e}")
return False
def main():
"""Main setup function"""
print("=" * 60)
print("ALPR System - Setup and Verification")
print("=" * 60)
results = {
'Python Version': check_python_version(),
'CUDA': check_cuda(),
'Dependencies': check_dependencies(),
'Directories': create_directories(),
'Models': download_models(),
'Camera': test_camera()
}
print("\n" + "=" * 60)
print("Setup Summary")
print("=" * 60)
for name, status in results.items():
symbol = "✓" if status else "❌"
print(f"{symbol} {name}")
all_good = all(results.values())
print("\n" + "=" * 60)
if all_good:
print("✓ Setup complete! You can now run: python main.py")
else:
print("⚠ Some checks failed. Please review and fix issues above.")
print("=" * 60)
return 0 if all_good else 1
if __name__ == "__main__":
sys.exit(main())