'Coordinates of hand landmarks are not displayed in mediapipe hands
I'm trying to create a dataset consisting of hand landmark coordinates obtained using mediapipe to train a neural network:
import cv2
import mediapipe
import sys
import os.path
signs = {'up': 0, 'down': 1, 'right': 2, 'left': 3}
drawingModule = mediapipe.solutions.drawing_utils
handsModule = mediapipe.solutions.hands
capture = cv2.VideoCapture(0)
frameWidth = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
frameHeight = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
start = False
max_count = int(sys.argv[1])
counter = 0
with handsModule.Hands(static_image_mode=False, min_detection_confidence=0.7, min_tracking_confidence=0.7,
max_num_hands=1) as hands:
while (True):
# frame == 480 640
ret, frame = capture.read()
results = hands.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
cv2.rectangle(frame, (10, 30), (310, 330), (0, 255, 0), 2)
k = cv2.waitKey(1)
cv2.imshow('Test hand', frame)
if counter == max_count:
break
if k == ord('u'):
name = 'up'
if k == ord('d'):
name = 'down'
if k == ord('r'):
name = 'right'
if k == ord('l'):
name = 'left'
if k == ord('a'):
start = not start
if start:
data = []
roi = frame[25:335, 8:315]
hands_roi = hands.process(roi)
counter += 1
height, width, channels = roi.shape
if hands_roi.multi_hand_landmarks != None:
for handLandmarks in hands_roi.multi_hand_landmarks:
for point in handsModule.HandLandmark:
normalizedLandmark = handLandmarks.landmark[point]
pixelCoordinatesLandmark = drawingModule._normalized_to_pixel_coordinates(normalizedLandmark.x,
normalizedLandmark.y,
width, height)
print(pixelCoordinatesLandmark)
if os.path.exists('dataset.csv'):
columns = ['x11', 'x21', 'x12', 'x22', 'x13', 'x23', 'x14', 'x24', 'x15', 'x25',
'x16', 'x26', 'x17', 'x27', 'x18', 'x28', 'x19', 'x29', 'x110'
'x210', 'x111', 'x211', 'x112', 'x212', 'x113', 'x213', '114', '214', '115', 'x215',
'x116', 'x216', 'x117', 'x217', 'x118', 'x218', 'x119', 'x219', 'x120',
'x220', 'y']
if k == ord('q'):
break
cv2.destroyAllWindows()
capture.release()
But when I press 'a' and expect to get the coordinates of the hand landmarks I get nothing. How to fix it?⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
