From d4de4a8699640f35be23dcd385b4708c4d966577 Mon Sep 17 00:00:00 2001 From: Michal Maciaszek Date: Sun, 17 Jan 2021 14:16:01 +0100 Subject: [PATCH] SMART-61 write text with ninja --- client/gestures/gesture_recognition.py | 1 + client/gestures/simple_gestures_lib.py | 10 +++++++ client/views/project_view.py | 36 ++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/client/gestures/gesture_recognition.py b/client/gestures/gesture_recognition.py index 2606f01..e27c4f3 100644 --- a/client/gestures/gesture_recognition.py +++ b/client/gestures/gesture_recognition.py @@ -41,6 +41,7 @@ class MyVideoCapture: for hand_landmarks in results.multi_hand_landmarks: fingers['index'] = sgest.check_index_finger(hand_landmarks) fingers['start_stop'] = sgest.get_start_stop(hand_landmarks) + fingers['ninja'] = sgest.search_for_ninja_turtle(hand_landmarks) # fingers['middle'] = sgest.check_middle_finger(hand_landmarks) # fingers['ring'] = sgest.check_ring_finger(hand_landmarks) # fingers['pinky'] = sgest.check_pinky_finger(hand_landmarks) diff --git a/client/gestures/simple_gestures_lib.py b/client/gestures/simple_gestures_lib.py index 7e1f4fa..fb2b652 100644 --- a/client/gestures/simple_gestures_lib.py +++ b/client/gestures/simple_gestures_lib.py @@ -39,6 +39,16 @@ def get_start_stop(hand_landmarks): else: return 'nothing' +def search_for_ninja_turtle(hand_landmarks): + index_finger = check_index_finger(hand_landmarks) + pinky_finger = check_pinky_finger(hand_landmarks) + middle_finger = check_middle_finger(hand_landmarks) + ring_finger = check_ring_finger(hand_landmarks) + if index_finger['straight'] and pinky_finger['straight'] and not middle_finger['straight'] and not ring_finger['straight']: + #return 'ninja' + return {'ninja': 'ninja', 'x': index_finger['x'], 'y': index_finger['y']} + else: + return 'nothing' def check_index_finger(hand_landmarks): return check_finger(hand_landmarks, INDEX_FINGER_TOP, INDEX_FINGER_BOTTOM) diff --git a/client/views/project_view.py b/client/views/project_view.py index 3072c22..4155d2a 100644 --- a/client/views/project_view.py +++ b/client/views/project_view.py @@ -2,6 +2,7 @@ import PIL.Image import PIL.ImageTk import tkinter as tk import os +import cv2 from constants import PROJECT_VIEW_NAME, FONT, PROJECTS_VIEW_NAME from gestures.gesture_recognition import MyVideoCapture @@ -27,8 +28,8 @@ class ProjectView(tk.Frame, AbstractView): self.save_button = None self.bottom_frame = None self.top_frame = None - self.first_time=True - + self.first_time = True + self.flag_just_done = False @staticmethod def get_view_name() -> str: return PROJECT_VIEW_NAME @@ -61,6 +62,23 @@ class ProjectView(tk.Frame, AbstractView): self.update() + def create_window(self): + window = tk.Toplevel() + e1 = tk.Entry(window) + e1.grid(row=0, column=1) + okVar = tk.IntVar() + tk.Button(window,text = 'Write',command=lambda: okVar.set(1)).grid(row=1, + column=1, + sticky=tk.W, + pady=4) + #print(okVar) + self.window.wait_variable(okVar) + self.text_to_write = e1.get() + #print(self.text_to_write) + window.destroy() + #self.window.wait_window(window) + + def update(self): # Get a frame from the video source if self.vid is not None: @@ -68,14 +86,28 @@ class ProjectView(tk.Frame, AbstractView): if fingers is not None: index_finger = fingers['index'] start_stop = fingers['start_stop'] + if fingers['ninja'] != 'nothing' and self.flag_just_done == False: + #print('trying') + self.create_window() + + cv2.waitKey(10) + self.flag_just_done = True + x = index_finger['x'] + y = index_finger['y'] + x, y = self.scale_points(x, y) + self.canvas.create_text(x,y,fill="darkblue", text= self.text_to_write, tags='text') + if start_stop == 'start': print('start') self.start_draw = True self.first_time = True + + elif start_stop == 'stop': print('stop') self.start_draw = False self.first_time = False + self.flag_just_done = False if self.start_draw and index_finger['straight']: x = index_finger['x']