-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
142 lines (123 loc) · 4.6 KB
/
setup.py
File metadata and controls
142 lines (123 loc) · 4.6 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
"""
Setup script for Invisibility Cloak Project
Checks dependencies and provides installation guidance
"""
import subprocess
import sys
import importlib.util
def check_python_version():
"""Check if Python version is compatible"""
print("Checking Python version...")
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 7):
print(f"❌ Python {version.major}.{version.minor} detected")
print("❌ This project requires Python 3.7 or higher")
return False
else:
print(f"✅ Python {version.major}.{version.minor}.{version.micro} detected")
return True
def check_package(package_name, import_name=None):
"""Check if a package is installed"""
if import_name is None:
import_name = package_name
try:
spec = importlib.util.find_spec(import_name)
if spec is not None:
print(f"✅ {package_name} is installed")
return True
else:
print(f"❌ {package_name} is not installed")
return False
except ImportError:
print(f"❌ {package_name} is not installed")
return False
def install_package(package_name):
"""Install a package using pip"""
print(f"Installing {package_name}...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
print(f"✅ {package_name} installed successfully")
return True
except subprocess.CalledProcessError:
print(f"❌ Failed to install {package_name}")
return False
def check_camera():
"""Check if camera is accessible"""
try:
import cv2
cap = cv2.VideoCapture(0)
if cap.isOpened():
ret, frame = cap.read()
cap.release()
if ret:
print("✅ Camera is accessible")
return True
else:
print("❌ Camera found but cannot capture frames")
return False
else:
print("❌ Cannot access camera")
return False
except Exception as e:
print(f"❌ Camera check failed: {e}")
return False
def main():
"""Main setup function"""
print("=== Invisibility Cloak Setup ===")
print()
# Check Python version
if not check_python_version():
print("\nPlease upgrade your Python installation and try again.")
return False
print("\nChecking dependencies...")
# Required packages
packages = [
("opencv-python", "cv2"),
("numpy", "numpy")
]
missing_packages = []
for package_name, import_name in packages:
if not check_package(package_name, import_name):
missing_packages.append(package_name)
# Install missing packages
if missing_packages:
print(f"\nMissing packages: {', '.join(missing_packages)}")
response = input("Would you like to install them now? (y/n): ").lower().strip()
if response == 'y' or response == 'yes':
print("\nInstalling missing packages...")
for package in missing_packages:
if not install_package(package):
print(f"\nFailed to install {package}. Please install manually:")
print(f"pip install {package}")
return False
else:
print("\nPlease install the missing packages manually:")
for package in missing_packages:
print(f"pip install {package}")
return False
print("\n" + "="*50)
print("Checking camera access...")
if check_camera():
print("\n🎉 Setup completed successfully!")
print("\nYou can now run the invisibility cloak:")
print(" Basic version: python invisibility_cloak.py")
print(" Advanced version: python advanced_invisibility_cloak.py")
print("\nTips for best results:")
print(" - Use bright, solid red colored fabric")
print(" - Ensure good lighting conditions")
print(" - Keep the background stationary")
return True
else:
print("\n⚠️ Setup completed but camera access failed")
print("Please check:")
print(" - Camera is connected and working")
print(" - No other applications are using the camera")
print(" - Camera drivers are up to date")
return False
if __name__ == "__main__":
success = main()
if not success:
print("\n❌ Setup encountered issues. Please resolve them and try again.")
sys.exit(1)
else:
print("\n✅ Setup completed successfully!")