Skip to content

Commit

Permalink
Merge pull request #10 from suhas-arun/feature/integrate-gestures
Browse files Browse the repository at this point in the history
Feature/integrate gestures
  • Loading branch information
benJames9 authored Feb 4, 2024
2 parents f03015f + f4027ba commit 0629930
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
11 changes: 10 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# python base image
FROM python:3.9
FROM python:3.11.0

# Workdir for output
WORKDIR /app

# Install dependencies required for OpenCV and GLib
RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \
libglib2.0-0 \
ffmpeg \
libsm6 \
libxext6 \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements.txt to workdir
COPY requirements.txt .

Expand Down
1 change: 0 additions & 1 deletion backend/gesreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from mediapipe.tasks import python
from mediapipe.tasks.python import vision


def get_fingers (image_source, model_source):

base_options = python.BaseOptions(model_asset_path=model_source)
Expand Down
8 changes: 6 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from facereg import face_to_name
from facereg import nearest_hand
from gesreg import get_fingers
from PIL import Image

app = FastAPI()

Expand All @@ -25,13 +26,17 @@
file_counter_lock = asyncio.Lock()
files_path = "../uploads"

# Ensure the target directory exists
os.makedirs(files_path, exist_ok=True)

def perform_analysis(image_path: str, model_source: str):
guesses = {}
faces = face_to_name(image_path)
fingers = get_fingers(image_path, model_source)
for name, face_coords in faces.items():
answer = nearest_hand(face_coords[0], face_coords[1], fingers)
guesses[name] = answer
print(guesses)
return guesses

async def get_next_filename() -> str:
Expand All @@ -42,7 +47,6 @@ async def get_next_filename() -> str:

@app.get("/")
def read_root():
print(perform_analysis("Upload/Test3.jpeg", "Models/gesture_recognizer-7.task"))
return {"Hello": "World"}

@app.post("/scan")
Expand All @@ -62,7 +66,7 @@ async def receive_image(file: UploadFile = File(...)):
img.save(path_to_file, "PNG")

# Perform image analysis
result = perform_analysis(path_to_file)
result = perform_analysis(path_to_file, "Models/gesture_recognizer-7.task")

# Delete the file after analysis
os.remove(path_to_file)
Expand Down
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ mediapipe==0.10.0
pandas==2.1.4
pillow>=10.1
python-multipart
mediapipe==0.10.0

0 comments on commit 0629930

Please sign in to comment.