-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WindowService and Some improvements * Hand Tracking Example and Some improvements * Delete .DS_Store
- Loading branch information
1 parent
7e397a4
commit caeda2a
Showing
14 changed files
with
803 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,6 @@ cython_debug/ | |
|
||
# PyCharm | ||
.idea/ | ||
|
||
# MacOS | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
import cv2 | ||
from PIL import Image | ||
|
||
from eymos import Service, log | ||
from eymos.services import FrameType | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"timer": { | ||
"max_time": 300 | ||
}, | ||
"hand_tracking": { | ||
"model_complexity": 0, | ||
"min_detection_confidence": 0.5, | ||
"min_tracking_confidence": 0.5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from eymos import ServiceManager, log | ||
from eymos.services import CameraService, WindowService | ||
from services.hand_tracking import HandTrackingService | ||
|
||
|
||
# Initialize the service manager | ||
manager = ServiceManager() | ||
|
||
# Add the services to the manager | ||
camera = manager.add("camera", CameraService) | ||
window = manager.add("window", WindowService) | ||
hand_tracking = manager.add("hand_tracking", HandTrackingService) | ||
|
||
# Start the services | ||
manager.start() | ||
|
||
# Start the window main loop | ||
log("Starting tkinter main loop...") | ||
window.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import cv2 | ||
import mediapipe as mp | ||
from eymos import Service | ||
|
||
|
||
class HandTrackingService(Service): | ||
def init(self): | ||
"""Initialize the service.""" | ||
# Setting up initial attributes | ||
self._loop_delay = 0.04 # Delay between each loop | ||
self.__hand_detector = None # Placeholder for the hand detection model | ||
self.__model_complexity = self._config.get('model_complexity', 0) # Simplified hand model for real-time | ||
self.__min_detection_confidence = self._config.get('min_detection_confidence', 0.5) # Minimum confidence to detect hands | ||
self.__min_tracking_confidence = self._config.get('min_tracking_confidence', 0.5) # Minimum confidence to track hands | ||
|
||
def destroy(self): | ||
"""Clean up resources before stopping the service.""" | ||
if self.__hand_detector: | ||
self.__hand_detector.close() # Clean up MediaPipe hand detector | ||
self._hand_detector = None | ||
self._model_complexity = None | ||
self._min_detection_confidence = None | ||
self._min_tracking_confidence = None | ||
|
||
def before(self): | ||
"""Prepare anything that needs to be initialized outside the main thread.""" | ||
self.__hand_detector = mp.solutions.hands.Hands( | ||
model_complexity=self.__model_complexity, | ||
min_detection_confidence=self.__min_detection_confidence, | ||
min_tracking_confidence=self.__min_tracking_confidence | ||
) | ||
|
||
def loop(self): | ||
"""Main loop where the hand detection logic will run.""" | ||
# Get the CameraService from the service manager | ||
camera_service = self._services.get('camera') | ||
if camera_service is None: | ||
return | ||
|
||
# Get the latest frame from CameraService | ||
frame = camera_service.get_frame() | ||
if frame is None: | ||
return | ||
|
||
# Convert the frame from BGR to RGB as required by MediaPipe | ||
image_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | ||
|
||
# Process the frame to detect hands | ||
results = self.__hand_detector.process(image_rgb) | ||
|
||
# If hands are detected, draw landmarks on the frame | ||
if results.multi_hand_landmarks: | ||
for hand_landmarks in results.multi_hand_landmarks: | ||
mp.solutions.drawing_utils.draw_landmarks( | ||
frame, hand_landmarks, mp.solutions.hands.HAND_CONNECTIONS | ||
) | ||
|
||
# Display the processed frame in WindowService | ||
window_service = self._services.get('window') | ||
if window_service: | ||
window_service.draw(frame) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import time | ||
|
||
from eymos.service_manager import ServiceManager | ||
from services.timer import TimerService | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# eymos/services/__init__.py | ||
|
||
from .camera import CameraService, FrameType | ||
from .window import WindowService, ImageSize | ||
|
||
__all__ = ['CameraService', 'FrameType'] | ||
__all__ = ['CameraService', 'FrameType', 'WindowService', 'ImageSize'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.