Skip to content
Open
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
4,506 changes: 0 additions & 4,506 deletions _/T5-MDLCC.ipynb

This file was deleted.

Binary file removed _/best2.pt
Binary file not shown.
2 changes: 1 addition & 1 deletion labels/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def step_face(self):
int(self.pose.y() + (self.target.y() - self.pose.y()) * 0.3)
)

def face_detectio_target(self, x, y):
def face_tracking_target(self, x, y):
self.target = QPoint(
int(self.width() * x * 0.6 + self.width() * 0.15),
int(self.height() * y * 0.8 + self.height() * 0.1)
Expand Down
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import sys

LLM = False
FACE_DETECTION = False
FACE_TRACKING = True

if __name__ == "__main__":

app = QApplication(sys.argv)

window = MainWindow()

if FACE_DETECTION:
from modules.face_detection import FaceDetection
if FACE_TRACKING:
from modules.face_tracking import FaceTracking

facedetection = FaceDetection()
faceTracking = FaceTracking()

window.signal_start_detection.connect(facedetection.start_detection)
window.signal_stop_detection.connect(facedetection.stop_detection)
facedetection.sender_pose.connect(window.face.face_detectio_target)
window.signal_start_tracking.connect(faceTracking.start_tracking)
window.signal_stop_tracking.connect(faceTracking.stop_tracking)
faceTracking.sender_pose.connect(window.face.face_tracking_target)

if LLM:
from modules.sst import SpeechToText
Expand Down
60 changes: 60 additions & 0 deletions modules/face_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import cv2
from cvzone.FaceDetectionModule import FaceDetector
from PyQt6.QtCore import pyqtSignal, QObject
from threading import Thread


class FaceTracking(QObject):

sender_pose = pyqtSignal(float, float)

def __init__(self):
super().__init__()
self.detector = FaceDetector()
self.state = 0

def start_tracking(self):
self.state = 1
connection_thread = Thread(target=self.track, daemon=True)
connection_thread.start()

def stop_tracking(self):
self.state = 0



def track(self):
cap = cv2.VideoCapture(0)
while self.state:
success, img = cap.read()
img, bboxs = self.detector.findFaces(img, draw=False)

if bboxs:
#get the coordinate
fx, fy = bboxs[0]["center"][0], bboxs[0]["center"][1]
pos = [fx, fy]



def track(self):
cap = cv2.VideoCapture(0)
while self.state:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
img, faces = self.detector.findFaces(frame, draw=False)
if faces:
x, y = faces[0]["center"][0], faces[0]["center"][1]
# Show the camera and a point in the center of the face
# cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)
# cv2.imshow("Frame", frame)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
self.sender_pose.emit(
x / 640,
y / 480
)

else:
self.sender_pose.emit(0.5, 0.5)
cap.release()
cv2.destroyAllWindows()
13 changes: 7 additions & 6 deletions modules/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

class MainWindow(QMainWindow):

signal_start_detection = pyqtSignal()
signal_stop_detection = pyqtSignal()
signal_start_tracking = pyqtSignal()
signal_stop_tracking = pyqtSignal()

signal_start_listening = pyqtSignal()
signal_ajust_noise = pyqtSignal()
Expand All @@ -37,8 +37,8 @@ def set_layout(self):
self.webview.load(QUrl("https://v2.ubicate.osuc.dev/map?place=B12"))
self.webview.hide()

# self.layout.addWidget(self.face, 3)
# self.layout.addWidget(self.webview, 20)
self.layout.addWidget(self.face, 3)
self.layout.addWidget(self.webview, 20)

self.h_layout.addWidget(self.face, 1)
self.h_layout.addWidget(self.webview, 1)
Expand Down Expand Up @@ -86,10 +86,11 @@ def keyPressEvent(self, event):

if event.key() == Qt.Key.Key_D:
self.face.setMouseTracking(False)
self.signal_start_detection.emit()
self.signal_start_tracking.emit()

if event.key() == Qt.Key.Key_S:
self.face.setMouseTracking(True)
self.signal_stop_detection.emit()
self.signal_stop_tracking.emit()

if event.key() == Qt.Key.Key_L:
self.signal_start_listening.emit()
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ PyAudio == 0.2.14
pyttsx3 == 2.91
ollama == 0.3.1
PyQt6 == 6.7.0
torch == 2.4.0+cu124
torch == 2.4.0+cu124
cvzone == 1.6.1
mediapipe == 0.10.14