-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
139 lines (113 loc) · 3.73 KB
/
Copy pathsetup.py
File metadata and controls
139 lines (113 loc) · 3.73 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
#!/usr/bin/env python3
"""
Setup script for RTSP Vehicle Detection System
Academic Research Project
This script helps install dependencies and configure the system.
"""
import subprocess
import sys
import os
def check_python_version():
"""Check if Python version is compatible."""
if sys.version_info < (3, 7):
print("❌ Python 3.7 or higher is required")
return False
print(f"✅ Python {sys.version_info.major}.{sys.version_info.minor} detected")
return True
def install_dependencies():
"""Install required Python packages."""
print("📦 Installing dependencies...")
dependencies = [
"opencv-python>=4.5.0",
"ultralytics>=8.0.0",
"numpy>=1.19.0",
"tensorflow>=2.0.0",
"dataclasses;python_version<'3.7'"
]
for dep in dependencies:
print(f"Installing {dep}...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", dep])
print(f"✅ {dep} installed successfully")
except subprocess.CalledProcessError:
print(f"❌ Failed to install {dep}")
return False
return True
def test_imports():
"""Test if all required modules can be imported."""
print("🔍 Testing imports...")
modules = [
("cv2", "OpenCV"),
("ultralytics", "Ultralytics YOLO"),
("numpy", "NumPy"),
("tensorflow", "TensorFlow")
]
for module_name, display_name in modules:
try:
__import__(module_name)
print(f"✅ {display_name} imported successfully")
except ImportError as e:
print(f"❌ Failed to import {display_name}: {e}")
return False
return True
def create_directories():
"""Create necessary directories."""
print("📁 Creating directories...")
directories = [
"detection_output",
"logs"
]
for directory in directories:
try:
os.makedirs(directory, exist_ok=True)
print(f"✅ Created directory: {directory}")
except Exception as e:
print(f"❌ Failed to create directory {directory}: {e}")
return False
return True
def test_rtsp_support():
"""Test if OpenCV supports RTSP."""
print("🔍 Testing RTSP support...")
try:
import cv2
# Try to create a VideoCapture object (this tests RTSP support)
cap = cv2.VideoCapture()
cap.release()
print("✅ OpenCV RTSP support available")
return True
except Exception as e:
print(f"❌ RTSP support test failed: {e}")
return False
def main():
"""Main setup function."""
print("🚗 RTSP Vehicle Detection System Setup")
print("=" * 50)
# Check Python version
if not check_python_version():
return False
# Install dependencies
if not install_dependencies():
print("❌ Failed to install dependencies")
return False
# Test imports
if not test_imports():
print("❌ Import test failed")
return False
# Test RTSP support
if not test_rtsp_support():
print("❌ RTSP support test failed")
return False
# Create directories
if not create_directories():
print("❌ Failed to create directories")
return False
print("\n🎉 Setup completed successfully!")
print("\n📋 Next steps:")
print("1. Configure your RTSP URL in the scripts")
print("2. Test connection: python3 test_rtsp.py")
print("3. Run detection: python3 run_detection.py")
print("\n📖 For more information, see README_RTSP.md")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)