forked from PearlAngeline/Fake-Drug-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_and_run.py
More file actions
71 lines (60 loc) · 2.15 KB
/
Copy pathsetup_and_run.py
File metadata and controls
71 lines (60 loc) · 2.15 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
#!/usr/bin/env python3
"""
Setup and run script for barcode scanner
This script handles installation of dependencies and runs the barcode scanner
"""
import subprocess
import sys
import os
def install_requirements():
"""Install required packages"""
print("Installing required packages...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("✓ All packages installed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Error installing packages: {e}")
return False
def check_tesseract():
"""Check if Tesseract OCR is installed"""
try:
result = subprocess.run(['tesseract', '--version'],
capture_output=True, text=True, check=True)
print("✓ Tesseract OCR is installed")
return True
except (subprocess.CalledProcessError, FileNotFoundError):
print("✗ Tesseract OCR not found!")
print("Please install Tesseract OCR:")
print(" - macOS: brew install tesseract")
print(" - Ubuntu/Debian: sudo apt-get install tesseract-ocr")
print(" - Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki")
return False
def main():
print("Barcode Scanner Setup")
print("=" * 30)
# Check if images folder exists
if not os.path.exists("images"):
print("✗ Images folder not found!")
print("Please make sure you have an 'images' folder with your images.")
return
# Install Python packages
if not install_requirements():
return
# Check Tesseract
if not check_tesseract():
return
print("\n" + "=" * 30)
print("Setup complete! Running barcode scanner...")
print("=" * 30)
# Run the barcode scanner
try:
from barcode_scanner import BarcodeTextScanner
scanner = BarcodeTextScanner()
scanner.process_all_images()
except ImportError as e:
print(f"Error importing barcode scanner: {e}")
except Exception as e:
print(f"Error running scanner: {e}")
if __name__ == "__main__":
main()