git clone https://github.com/NatBuilds/TerminalOS.git
cd TerminalOS
pip install -r requirements.txt
python run.pyThree powerful libraries have been successfully integrated into the TerminalOS application, providing comprehensive device automation, image processing, and OCR capabilities.
- Class:
ADBController+ADBDeviceInfo - Purpose: Control Android devices via ADB
- Key Methods:
- Device management:
devices(),connect(),disconnect() - Input control:
tap(),press(),hold(),swipe(),talk() - App management:
open_app(),is_app_running(),install(),uninstall() - File transfer:
push(),pull(),screenshot() - Shell execution:
shell() - Device info:
current_foreground_app(),running_processes()
- Device management:
- Class:
OpenCVImageTools - Purpose: Image processing and computer vision
- Key Methods:
- I/O:
load_image(),save_image(),create_blank() - Colors:
to_grayscale(),normalize_brightness() - Filters:
blur(),median_blur(),threshold(),detect_edges() - Transform:
resize(),rotate(),crop() - Draw:
draw_text(),draw_rectangle(),draw_circle(),annotate_box()
- I/O:
- Class:
TesseractOCR - Purpose: Optical Character Recognition (text extraction)
- Key Methods:
extract_text()- Get all text from imageextract_data()- Get text with positions and confidenceextract_boxes()- Get bounding boxesextract_pdf()- Generate searchable PDF
Interactive menu with 14 device control options:
-
ADB Utilities (11 options)
- List devices, Run shell commands, Send text
- Tap/Press/Hold/Swipe screen
- Open apps, Check running apps
- Show processes, Show foreground app
-
Vision Tools (3 options)
- OpenCV image processing demo
- Tesseract text extraction
- Tesseract data output
Complete example showing all three libraries working together:
- Captures device screenshots via ADB
- Processes images with OpenCV (grayscale, blur, edges)
- Extracts text with Tesseract OCR
- Saves all outputs to
screenshots/directory - Includes extensive code comments explaining each step
Extended app/core/config.py with new configuration sections:
ADB Configuration (in app/config.json):
{
"adb": {
"adb_executable": "adb",
"device_serial": "",
"timeout": 30
}
}OCR Configuration (in app/config.json):
{
"ocr": {
"tesseract_cmd": "tesseract",
"language": "eng",
"psm": 3,
"oem": 3,
"timeout": 30
}
}Updated requirements.txt:
opencv-python>=4.10.0.84
pytesseract>=0.3.13
Additional system requirements:
- ADB: Android SDK Platform Tools (or system adb)
- Tesseract: System-wide installation (choco/brew/apt)
from app.libraries import ADBController, OpenCVImageTools, TesseractOCR
# All work the same way - instantiate and use
adb = ADBController()
cv = OpenCVImageTools()
ocr = TesseractOCR()
# Check availability (graceful degradation)
if not adb.is_available():
print("ADB not available")Run the application and navigate to:
- Device Tools → ADB Utilities or Vision Tools
- ADB Screenshot and read → Full end-to-end example
Edit app/config.json to customize paths and settings:
{
"adb": {
"adb_executable": "adb",
"device_serial": "specific_device_id",
"timeout": 60
},
"ocr": {
"tesseract_cmd": "/usr/bin/tesseract",
"language": "eng",
"psm": 3,
"oem": 3,
"timeout": 30
}
}-
Optional Dependencies: Libraries gracefully handle missing packages
cv = OpenCVImageTools() if not cv.is_available(): # Skip processing
-
Config-Driven: Read defaults from
app/config.json# These values come from config adb = ADBController()
-
Exception Handling: Operations return None/False on error, log via status
image = cv.load_image(path) if image is None: # Error was logged return
-
Cross-Platform: Use
pathlib.Pathfor all file operationspath = Path(screenshot_path).expanduser()
app/
├── libraries/
│ ├── adb/
│ │ ├── __init__.py
│ │ └── adb_controller.py # 370+ lines, 26 methods
│ ├── opencv/
│ │ ├── __init__.py
│ │ └── image_tools.py # 280+ lines, 20 methods
│ ├── ocr/
│ │ ├── __init__.py
│ │ └── tesseract_ocr.py # 160+ lines, 8 methods
│ └── __init__.py # Re-exports all classes
├── modules/
│ ├── device_tools/
│ │ ├── __init__.py
│ │ └── controller.py # 11 ADB + 3 Vision menu items
│ └── screenshot_analyzer/
│ ├── __init__.py
│ └── controller.py # 280+ lines with detailed comments
├── core/
│ ├── config.py # Extended with ADB + OCR getters
│ └── status.py # Use for all output
└── config.json # Extended with adb + ocr sections
All components have been tested:
- ✅ Syntax validation (Python compileall)
- ✅ Import validation
- ✅ Runtime instantiation
- ✅ Module discovery and registration
- ✅ Menu integration
- ✅ ADB device detection (with real device)
- ✅ OpenCV image operations (with real screenshots)
- ✅ Tesseract availability check
- ✅ Screenshot capture and processing workflow
- LIBRARIES_GUIDE.md - API reference and usage examples
- SCREENSHOT_ANALYZER_GUIDE.md - In-depth example walkthrough
- Inline code comments - Extensive comments in all implementations
- Comprehensive device control (30+ methods)
- Automatic device discovery
- Configurable executable path and timeout
- Error handling and status logging
- Cross-platform compatibility
- 20+ image processing methods
- Graceful handling of missing opencv-python
- Type-safe API with None returns on errors
- Low-level (cv2) access via helper methods
- Text extraction with confidence scores
- Multi-language support
- Detailed data extraction (positions, boxes)
- PDF generation capability
- Graceful handling of missing system binary
- Batch Processing - Process multiple devices/screenshots
- UI Automation - Use OCR results to find and tap UI elements
- Screenshot Comparison - Detect changes between screenshots
- Performance Optimization - Image caching, parallel processing
- Custom Workflows - Create domain-specific analysis modules
- Integration Testing - Automated UI testing with OCR verification
The implementation provides:
- ✅ 3 production-ready libraries (800+ lines of code)
- ✅ 2 demonstration modules with menu integration
- ✅ Comprehensive configuration system
- ✅ Graceful degradation for optional dependencies
- ✅ Extensive documentation and examples
- ✅ Tested and working with real devices
- ✅ Follows existing app conventions and patterns
All libraries are accessible via from app.libraries import ... and integrate seamlessly with the CLI menu system.