SMART-61 write text with ninja

This commit is contained in:
Michal Maciaszek 2021-01-17 14:16:01 +01:00
parent 11a43331ad
commit d4de4a8699
3 changed files with 45 additions and 2 deletions

View File

@ -41,6 +41,7 @@ class MyVideoCapture:
for hand_landmarks in results.multi_hand_landmarks: for hand_landmarks in results.multi_hand_landmarks:
fingers['index'] = sgest.check_index_finger(hand_landmarks) fingers['index'] = sgest.check_index_finger(hand_landmarks)
fingers['start_stop'] = sgest.get_start_stop(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['middle'] = sgest.check_middle_finger(hand_landmarks)
# fingers['ring'] = sgest.check_ring_finger(hand_landmarks) # fingers['ring'] = sgest.check_ring_finger(hand_landmarks)
# fingers['pinky'] = sgest.check_pinky_finger(hand_landmarks) # fingers['pinky'] = sgest.check_pinky_finger(hand_landmarks)

View File

@ -39,6 +39,16 @@ def get_start_stop(hand_landmarks):
else: else:
return 'nothing' 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): def check_index_finger(hand_landmarks):
return check_finger(hand_landmarks, INDEX_FINGER_TOP, INDEX_FINGER_BOTTOM) return check_finger(hand_landmarks, INDEX_FINGER_TOP, INDEX_FINGER_BOTTOM)

View File

@ -2,6 +2,7 @@ import PIL.Image
import PIL.ImageTk import PIL.ImageTk
import tkinter as tk import tkinter as tk
import os import os
import cv2
from constants import PROJECT_VIEW_NAME, FONT, PROJECTS_VIEW_NAME from constants import PROJECT_VIEW_NAME, FONT, PROJECTS_VIEW_NAME
from gestures.gesture_recognition import MyVideoCapture from gestures.gesture_recognition import MyVideoCapture
@ -28,7 +29,7 @@ class ProjectView(tk.Frame, AbstractView):
self.bottom_frame = None self.bottom_frame = None
self.top_frame = None self.top_frame = None
self.first_time = True self.first_time = True
self.flag_just_done = False
@staticmethod @staticmethod
def get_view_name() -> str: def get_view_name() -> str:
return PROJECT_VIEW_NAME return PROJECT_VIEW_NAME
@ -61,6 +62,23 @@ class ProjectView(tk.Frame, AbstractView):
self.update() 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): def update(self):
# Get a frame from the video source # Get a frame from the video source
if self.vid is not None: if self.vid is not None:
@ -68,14 +86,28 @@ class ProjectView(tk.Frame, AbstractView):
if fingers is not None: if fingers is not None:
index_finger = fingers['index'] index_finger = fingers['index']
start_stop = fingers['start_stop'] 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': if start_stop == 'start':
print('start') print('start')
self.start_draw = True self.start_draw = True
self.first_time = True self.first_time = True
elif start_stop == 'stop': elif start_stop == 'stop':
print('stop') print('stop')
self.start_draw = False self.start_draw = False
self.first_time = False self.first_time = False
self.flag_just_done = False
if self.start_draw and index_finger['straight']: if self.start_draw and index_finger['straight']:
x = index_finger['x'] x = index_finger['x']