Ключевые точки рук для отслеживания Mediapipe
Выполнение расчета расстояний между кончиками пальцев (всего 8 значений)
Это работает хорошо!
import mediapipe as mp
import cv2
import numpy as np
import rtmidi
out = rtmidi.MidiOut()
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
#Distance between Fingertips & MIDI Out
point_list = [[4,8],[8,12],[12,16],[16,20]]
def draw_tip_distances(image, results, point_list):
# Loop through hands
for hand in results.multi_hand_landmarks:
#Loop through point sets
for index, point in enumerate(point_list):
a = np.array([hand.landmark[point[0]].x, hand.landmark[point[0]].y]) # First coord
b = np.array([hand.landmark[point[1]].x, hand.landmark[point[1]].y]) # Second coord
dist = np.linalg.norm((a-b)*2.5)
if dist > 1:
dist = 1
if dist < 0.08:
dist = 0
cc_msg = [0xB0, 1, round(dist*127,0)]
out.send_message(cc_msg)
print(cc_msg)
cv2.putText(image, str(round(dist, 2)), tuple(np.multiply(b, [640, 480]).astype(int)),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2, cv2.LINE_AA)
return image
Текущий вывод
Где: [MIDI-канал, канал устройства, значение][176, 1, 52.0]
[176, 2, 16.0]
[176, 3, 11.0]
[176, 4, 12.0]
[176, 1, 46.0]
[176, 2, 12.0]
[176, 3, 14.0]
[176, 4, 15.0]
Желаемый результат
[176, 1, 57.0][176, 2, 14.0]
[176, 3, 0]
[176, 4, 25.0]
[176, 5, 70.0]
[176, 6, 21.0]
[176, 7, 12.0]
[176, 8, 24.0]
Подробнее здесь: https://stackoverflow.com/questions/792 ... array-loop
Мобильная версия