Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Distinguishing between the landmarks (left hand and right hand)

$
0
0

I have been trying to distinguish between the landmark with the same number for the left-hand and right-hand in mediapipe and opencv. The problem is that we have 20 id numbers but for both hands we have 40 landmarks. Eventually I want to extract the coordinates of for example landmark#8 on the left-hand and right-hand separately. Here is the minimal work I have done so far to put markers with different colors (circles) on the landmarks with the same number on the the left and right hands but it did not work (They get the same color again):

import cv2import mediapipe as mpimport timecap = cv2.VideoCapture(0)mpHands = mp.solutions.handshands = mpHands.Hands(max_num_hands=2)mpDraw = mp.solutions.drawing_utilswhile True:    success, img = cap.read()img = cv2.flip(img, 1) time.sleep(0.1)imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)results = hands.process(imgRGB)if results.multi_hand_landmarks:    for handLms in results.multi_hand_landmarks:                for id, lm in enumerate(handLms.landmark):            h,w,c = img.shape                cx, cy, cz = int(lm.x*w), int (lm.y*h) , int (lm.z*c)            lbl = results.multi_handedness[0].classification[0].label            if lbl == 'Right':                if id == 8:                    cv2.circle(img, (cx,cy),8, (255,0,0), cv2.FILLED)            if lbl == 'Left':                if id == 8 :                    cv2.circle(img, (cx,cy),8, (255,255,0), cv2.FILLED)        mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS,\            mpDraw.DrawingSpec(color=(121,0,255)),\                mpDraw.DrawingSpec(color=(0,255,0)))cv2.imshow("image", img)c = cv2.waitKey(7) % 0x100if c == 27:    break

I was hoping there is a solution to fully distinguish between all 40 landmarks for both hands.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>