Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #40 from LimaoC/mitch-notebook-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellJC authored Sep 3, 2024
2 parents 50bcb3b + 6c4e7aa commit 8b25034
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 22 deletions.
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@ You can check that the `sitting-desktop-garden` package has been installed corre
poetry run pip list | grep sitting-desktop-garden
```

## Raspberry Pi Setup
### Downloading ML Models
From top-level directory.
```bash
mkdir client/models/resources &&
curl -o client/models/resources/pose_landmarker_lite.task \
https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/latest/pose_landmarker_lite.task
```
### Installing Camera Drivers for OpenCV
Run the following command on the Raspberry Pi to install the necessary camera driver. This driver should come with the Raspberry Pi OS.
```bash
sudo modprobe bcm2835-v4l2
```
To test if this is successfuly installed.
```bash
ls -ltrh /dev/video*
```

### Deployment
To deploy a build to the Raspberry Pi use the `deploy.sh` script. This script will create a tarball of file listed in a text file, transfer it to
a specified hostname and untar it there.

To use the script execute it in the project's root directory with,
```bash
./deploy.sh [pathfile] [hostname] [username]
```
For example, to deploy the files listed in `deploypaths.txt` to `testpi` (using username raspberry) the command would be
```bash
./deploy.sh deploypaths.txt testpi raspberry
```
The pathname file should contain a path to a file or directory on each line. If a directory is listed `deploy.sh` will copy the entire contents over.
You can use the `#` character at the start of a line to leave comments.
## Development

To add a new dependency to the package, use
Expand Down Expand Up @@ -80,21 +112,6 @@ To run a specific test, say `test_dummy.py`, use
poetry run pytest tests/test_dummy.py
```

## Deployment
To deploy a build to the Raspberry Pi use the `deploy.sh` script. This script will create a tarball of file listed in a text file, transfer it to
a specified hostname and untar it there.

To use the script execute it in the project's root directory with,
```bash
./deploy.sh [pathfile] [hostname] [username]
```
For example, to deploy the files listed in `deploypaths.txt` to `testpi` (using username raspberry) the command would be
```bash
./deploy.sh deploypaths.txt testpi raspberry
```
The pathname file should contain a path to a file or directory on each line. If a directory is listed `deploy.sh` will copy the entire contents over.
You can use the `#` character at the start of a line to leave comments.

## Code Styling

We use [black](https://black.readthedocs.io/en/stable/) for automated code formatting. To run Black, run this command from the root of the repo:
Expand All @@ -119,10 +136,3 @@ This spins up a local server which serves the documentation pages, and also hot-

You can build the documentation (without spinning up a server) with `make docs`, and clean the documentation output with `make docs-clean`.

## Downloading ML Models
From top-level directory.
```bash
mkdir client/models/resources &&
curl -o client/models/resources/pose_landmarker_lite.task \
https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/latest/pose_landmarker_lite.task
```
35 changes: 35 additions & 0 deletions notebooks/scripts/explore-deepface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pprint import pprint
import cv2
from deepface import DeepFace


ENTER_ASCII = 13


def take_photo(photo_name):
capture = cv2.VideoCapture(0)
while True:
success, frame = capture.read()
if not success:
continue

cv2.imshow(f"Camera Preview for {photo_name}: Press enter to take photo", frame)

if cv2.waitKey(1) & 0xFF == ENTER_ASCII:
cv2.imwrite(photo_name, frame)

break

capture.release()
cv2.destroyAllWindows()


# Take two photos. Press enter to confirm photo.
print("Please take two photos")
take_photo("photo1.png")
take_photo("photo2.png")


# Verify that photos are of same person.
print("Deepface output")
pprint(DeepFace.verify("photo1.png", "photo2.png", model_name="GhostFaceNet"))
38 changes: 38 additions & 0 deletions notebooks/scripts/test-database-tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import time
from pprint import pprint
from datetime import datetime
from data.routines import (
init_database,
get_schema_info,
create_user,
save_posture,
get_users,
get_postures,
get_user_postures,
Posture,
)

print("Initialising database")
init_database()

print("Schema info")
pprint(get_schema_info())

print("Creating user")
create_user()

print("Getting 10 users")
pprint(get_users(num=10))

print("Adding posture for user 1")
time1 = datetime.now()
time.sleep(1)
time2 = datetime.now()
posture = Posture(None, 1, 0.8, 1.0, time1, time2)
save_posture(posture)

print("Getting 10 postures")
pprint(get_postures(num=10))

print("Getting postures for user 1")
pprint(get_user_postures(1))
24 changes: 24 additions & 0 deletions notebooks/scripts/test-posture-tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import cv2
from models.pose_detection.routines import (
DebugPostureTracker,
create_debug_posture_tracker,
)


def run_posture_tracking_loop(posture_tracker: DebugPostureTracker):
while True:
# Other control flow code
# ...

posture_tracker.track_posture()

# ...
# Other control flow code

# Quit when q is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break


with create_debug_posture_tracker() as posture_tracker:
run_posture_tracking_loop(posture_tracker)

0 comments on commit 8b25034

Please sign in to comment.