Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.venv
__pycache__
*.pyc
models/*.onnx
models/*.task
23 changes: 23 additions & 0 deletions python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies commonly needed by OpenCV/MediaPipe at runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
libglib2.0-0 \
libgl1 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN python -m pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt

# Download YOLOX-S phone detection model into the image
RUN mkdir -p models && \
python -c "import urllib.request; urllib.request.urlretrieve('https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx', 'models/yolox_s.onnx')"
Comment on lines +17 to +19

COPY . .

CMD ["python", "-m", "compileall", "."]
22 changes: 22 additions & 0 deletions python/cv/phone_image_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import cv2

from phone_detector import detect_phone


def main():
if len(sys.argv) < 2:
raise SystemExit("Usage: python cv/phone_image_test.py <image_path>")

image_path = sys.argv[1]
frame = cv2.imread(image_path)

if frame is None:
raise SystemExit(f"Could not read image: {image_path}")

result = detect_phone(frame)
print(result)


if __name__ == "__main__":
main()
121 changes: 121 additions & 0 deletions python/docker_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Taskmaster CV Worker

Computer vision worker responsible for phone detection and future focus monitoring features.

## Option 1: Docker (recommended)

No local Python setup required.

Build the image:

```bash
docker build -t taskmaster-cv-worker ./python
```

Run image-based detection:

```bash
docker run --rm taskmaster-cv-worker python cv/phone_image_test.py test_assets/phone_sample.jpg
```

Expected output:

```text
{'type': 'phone', 'status': 'detected', ...}
```

This uses a sample image and does not require a webcam.

---

## Option 2: Local development

Recommended for webcam testing.

Create a virtual environment:

```bash
cd python
python3.11 -m venv .venv
```

Activate it:

Linux/macOS:

```bash
source .venv/bin/activate
```

Windows:

```powershell
.\.venv\Scripts\Activate.ps1
```

Install dependencies:

```bash
pip install -r requirements.txt
```

Download the model:

```bash
./setup.sh
```

Run webcam test:

```bash
python cv/phone_detect_test.py
```

Run detection loop:

```bash
python cv/detection_loop.py
```

---

## Install Docker

### Windows / macOS

Download Docker Desktop:

https://www.docker.com/products/docker-desktop/

Verify installation:

```bash
docker --version
docker run hello-world
```

### Ubuntu

```bash
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
```

Verify installation:

```bash
docker --version
docker run hello-world
```

---

## Notes

- Python 3.11 is required.
- The YOLOX-S model is not committed to Git.
- Docker downloads the model during image build.
- Docker is intended for environment consistency and automated testing.
- Webcam testing is currently easier to perform locally.
Binary file added python/test_assets/phone_sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading