Compare commits
No commits in common. "master" and "gestures" have entirely different histories.
@ -14,7 +14,7 @@ class MyVideoCapture:
|
|||||||
self.mp_drawing = mp.solutions.drawing_utils
|
self.mp_drawing = mp.solutions.drawing_utils
|
||||||
self.mp_hands = mp.solutions.hands
|
self.mp_hands = mp.solutions.hands
|
||||||
self.hands = self.mp_hands.Hands(
|
self.hands = self.mp_hands.Hands(
|
||||||
min_detection_confidence=0.7, min_tracking_confidence=0.7)
|
min_detection_confidence=0.5, min_tracking_confidence=0.5)
|
||||||
if not self.vid.isOpened():
|
if not self.vid.isOpened():
|
||||||
raise ValueError("Unable to open video source", 0)
|
raise ValueError("Unable to open video source", 0)
|
||||||
# Get video source width and height
|
# Get video source width and height
|
||||||
@ -41,8 +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)
|
||||||
else:
|
else:
|
||||||
|
@ -39,16 +39,6 @@ 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)
|
||||||
@ -78,7 +68,7 @@ def check_finger(hand_landmarks, top_idx, bottom_idx):
|
|||||||
by = hand_landmarks.landmark[0].y
|
by = hand_landmarks.landmark[0].y
|
||||||
distance_bottom_start = calculate_distance(ax, ay, bx, by)
|
distance_bottom_start = calculate_distance(ax, ay, bx, by)
|
||||||
|
|
||||||
if distance_bottom_start < distance_top_bottom + 0.05:
|
if distance_bottom_start < distance_top_bottom + 0.1:
|
||||||
straight = True
|
straight = True
|
||||||
else:
|
else:
|
||||||
straight = False
|
straight = False
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
tk
|
tk
|
||||||
requests
|
requests
|
||||||
cv
|
|
||||||
mediapipe
|
|
||||||
Pillow
|
|
@ -2,7 +2,6 @@ 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,8 +27,8 @@ class ProjectView(tk.Frame, AbstractView):
|
|||||||
self.save_button = None
|
self.save_button = None
|
||||||
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.other_gestures_flag_possible = False
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_view_name() -> str:
|
def get_view_name() -> str:
|
||||||
return PROJECT_VIEW_NAME
|
return PROJECT_VIEW_NAME
|
||||||
@ -62,71 +61,22 @@ 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:
|
||||||
fingers, frame, success = self.vid.get_frame()
|
fingers, frame, success = self.vid.get_frame()
|
||||||
if fingers is not None:
|
if fingers is not None:
|
||||||
index_finger = fingers['index']
|
index_finger = fingers['index']
|
||||||
middle_finger = fingers['middle']
|
|
||||||
start_stop = fingers['start_stop']
|
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':
|
if start_stop == 'start':
|
||||||
print('start')
|
print('start')
|
||||||
self.start_draw = True
|
self.start_draw = True
|
||||||
self.first_time = True
|
self.first_time = True
|
||||||
self.other_gestures_flag_possible = False
|
|
||||||
|
|
||||||
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.other_gestures_flag_possible = True
|
if self.start_draw and index_finger['straight']:
|
||||||
|
|
||||||
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']
|
x = index_finger['x']
|
||||||
y = index_finger['y']
|
y = index_finger['y']
|
||||||
@ -137,7 +87,6 @@ class ProjectView(tk.Frame, AbstractView):
|
|||||||
self.first_time = False
|
self.first_time = False
|
||||||
#print("first_time")
|
#print("first_time")
|
||||||
self.canvas.create_line(x, y, x+1, y+1, self.previous_x, self.previous_y, tags='point', width=3)
|
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_x = x
|
||||||
self.previous_y = y
|
self.previous_y = y
|
||||||
if success:
|
if success:
|
||||||
|
Loading…
Reference in New Issue
Block a user