Metadata-Version: 2.1
Name: perceptionpro
Version: 0.1.0
Summary: PerceptionPro is a package for computer vision tasks such as head pose estimation, eye tracking, and object detection.
Home-page: UNKNOWN
Author: Umar Balak
Author-email: umarbalak35@gmail.com
License: MIT
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: opencv-python
Requires-Dist: mediapipe
Requires-Dist: lytics
Requires-Dist: numpy

# PerceptionPro

**PerceptionPro** is a Python package designed for real-time monitoring and alert systems. It provides modular components for head pose estimation, eye tracking, and object detection, all integrated into a cohesive alert system.

## Features
- **Head Pose Estimation**: Tracks the orientation of the user's head in real-time.
- **Eye Tracking**: Detects and analyzes eye movements and gaze direction.
- **Object Detection**: Identifies objects in the background to ensure environment compliance.
- **Core**: Combines all modules for real-time monitoring and alert generation.

---

## Installation

```bash
pip install perceptionpro
```

## Usage
```python
import cv2
import time
import keyboard 
import perceptionpro
from perceptionpro.core import perceptionproInit

def main():
    """
    Main function to initialize the camera, process video frames,
    and handle user input to quit.
    """
    try:
        # Initialize the camera
        camera = cv2.VideoCapture(0)

        if not camera.isOpened():
            print("Error: Camera could not be opened.")
            return
        else:
            print("Camera opened successfully.")

        # Initialize the perceptionproInit with speech enabled
        perceptionpro = perceptionproInit(camera, model_path="https://github.com/UmarBalak/perceptionpro/raw/refs/heads/main/yolov8s.pt")

        # Initialize variables
        violation_count = 0
        prev_time = time.time()

        while True:
            # Capture frame-by-frame
            ret, frame = camera.read()

            if not ret:
                print("Failed to capture video. Check your camera connection.")
                break

            # Calculate frame rate
            current_time = time.time()
            elapsed_time = current_time - prev_time
            fps = 1 / elapsed_time if elapsed_time > 0 else 0
            prev_time = current_time

            # Process frame metrics
            result, eye_d, head_d, fps, obj_d, alert_msg = perceptionpro.track()
            print("Procesed")

            if not result:
                violation_count += 1
                print(f"Warning: {violation_count} - {alert_msg}")

                if violation_count == 4:
                    print("The exam has been terminated.")
                    break
            else:
                pass
                # Print real-time metrics to console
                print(f"FPS: {fps:.2f}")
                print(f"Eye Direction: {eye_d}")
                print(f"Head Direction: {head_d}")
                print(f"Background: {'Ok' if obj_d else 'Object detected'}")

            # Check if 'q' is pressed to exit the loop
            if keyboard.is_pressed('q'):
                print("User requested to stop the process.")
                break

    except Exception as e:
        print(f"An unexpected error occurred: {e}")

    finally:
        # Always release the camera and close windows
        if 'camera' in locals() and camera.isOpened():
            camera.release()
        print("Camera released. Process complete.")

if __name__ == "__main__":
    main()
```

