SMART-61 write text with ninja
This commit is contained in:
parent
11a43331ad
commit
d4de4a8699
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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']
|
||||
|
Loading…
Reference in New Issue
Block a user