Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
47ca224e2a | |||
7dd4af8db2 | |||
|
def7acc30c | ||
6872124632 | |||
|
02c34ca299 | ||
|
d4de4a8699 |
@ -14,7 +14,7 @@ class MyVideoCapture:
|
||||
self.mp_drawing = mp.solutions.drawing_utils
|
||||
self.mp_hands = mp.solutions.hands
|
||||
self.hands = self.mp_hands.Hands(
|
||||
min_detection_confidence=0.5, min_tracking_confidence=0.5)
|
||||
min_detection_confidence=0.7, min_tracking_confidence=0.7)
|
||||
if not self.vid.isOpened():
|
||||
raise ValueError("Unable to open video source", 0)
|
||||
# Get video source width and height
|
||||
@ -41,7 +41,8 @@ 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['middle'] = sgest.check_middle_finger(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)
|
||||
else:
|
||||
|
@ -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)
|
||||
@ -68,7 +78,7 @@ def check_finger(hand_landmarks, top_idx, bottom_idx):
|
||||
by = hand_landmarks.landmark[0].y
|
||||
distance_bottom_start = calculate_distance(ax, ay, bx, by)
|
||||
|
||||
if distance_bottom_start < distance_top_bottom + 0.1:
|
||||
if distance_bottom_start < distance_top_bottom + 0.05:
|
||||
straight = True
|
||||
else:
|
||||
straight = False
|
||||
|
@ -1,2 +1,5 @@
|
||||
tk
|
||||
requests
|
||||
cv
|
||||
mediapipe
|
||||
Pillow
|
@ -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.other_gestures_flag_possible = False
|
||||
@staticmethod
|
||||
def get_view_name() -> str:
|
||||
return PROJECT_VIEW_NAME
|
||||
@ -61,22 +62,71 @@ 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:
|
||||
fingers, frame, success = self.vid.get_frame()
|
||||
if fingers is not None:
|
||||
index_finger = fingers['index']
|
||||
middle_finger = fingers['middle']
|
||||
start_stop = fingers['start_stop']
|
||||
if fingers['ninja'] != 'nothing' and self.other_gestures_flag_possible == True:
|
||||
#print('trying')
|
||||
self.create_window()
|
||||
|
||||
cv2.waitKey(10)
|
||||
self.other_gestures_flag_possible = False
|
||||
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',font=("Purisa", 20))
|
||||
|
||||
if start_stop == 'start':
|
||||
print('start')
|
||||
self.start_draw = True
|
||||
self.first_time = True
|
||||
self.other_gestures_flag_possible = False
|
||||
|
||||
elif start_stop == 'stop':
|
||||
print('stop')
|
||||
self.start_draw = False
|
||||
self.first_time = False
|
||||
if self.start_draw and index_finger['straight']:
|
||||
self.other_gestures_flag_possible = True
|
||||
|
||||
if self.start_draw and index_finger['straight'] and middle_finger['straight']:
|
||||
|
||||
x = index_finger['x']
|
||||
y = index_finger['y']
|
||||
x, y = self.scale_points(x, y)
|
||||
if self.first_time == True:
|
||||
self.previous_x = x
|
||||
self.previous_y = y
|
||||
self.first_time = False
|
||||
#print("first_time")
|
||||
canvas_id = self.canvas.create_line(x, y, x + 2, y + 2, self.previous_x, self.previous_y, tags='point', width=3, fill = 'red')
|
||||
self.canvas.after(100, self.canvas.delete, canvas_id)
|
||||
#self.canvas.create_line(x, y, x+1, y+1, self.previous_x, self.previous_y, tags='point', width=3)
|
||||
self.previous_x = x
|
||||
self.previous_y = y
|
||||
|
||||
if self.start_draw and index_finger['straight'] and not middle_finger['straight']:
|
||||
|
||||
x = index_finger['x']
|
||||
y = index_finger['y']
|
||||
@ -87,6 +137,7 @@ class ProjectView(tk.Frame, AbstractView):
|
||||
self.first_time = False
|
||||
#print("first_time")
|
||||
self.canvas.create_line(x, y, x+1, y+1, self.previous_x, self.previous_y, tags='point', width=3)
|
||||
|
||||
self.previous_x = x
|
||||
self.previous_y = y
|
||||
if success:
|
||||
|
Loading…
Reference in New Issue
Block a user