0

enter image description here

This is my hand landmark connection and I am only showing the circle only these landmarks.

handConnection = [(4, 4), (8, 8), (12, 12), (16, 16), (20, 20)]

Now I want to show a static image within these circle or circle postion.

enter image description here

Like I want to show five different images in these landmarks. How can I implement this. Here is the full code.

 import mediapipe as mp
import cv2
import cvzone

import numpy as np
import uuid
import os

mp_drawing = mp.solutions.drawing_utils
drawSpecific = mp.solutions.hands
mp_hands = mp.solutions.hands
handConnection = [(4, 4), (8, 8), (12, 12), (16, 16), (20, 20)]

cap = cv2.VideoCapture(0)
(ret, image) = cap.read()
imgFront = cv2.imread("poki.png", cv2.IMREAD_UNCHANGED)
imgFront = cv2.resize(imgFront, (0, 0), None, 0.3, 0.3)

hf, wf, cf = imgFront.shape
hb, wb, cb = image.shape

fpsReader = cvzone.FPS()
def main():
    hands = mp_hands.Hands(min_detection_confidence=0.7,
                           min_tracking_confidence=0.7)
    hand_landmark_drawing_spec = mp_drawing.DrawingSpec(color=(121, 22,
            6), thickness=5, circle_radius=0)
    hand_connection_drawing_spec = mp_drawing.DrawingSpec(color=(250,
            44, 90), thickness=15, circle_radius=15)

    while cap.isOpened():

        (ret, image) = cap.read()
        image = cv2.flip(image, 1)
        image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
        (image_height, image_width, _) = image.shape

        imgResult = cvzone.overlayPNG(image, imgFront, [0, hb - hf])
        _, imgResult = fpsReader.update(imgResult)

        results_hand = hands.process(image)
        image.flags.writeable = True
        image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

        if results_hand.multi_hand_landmarks:
            for (idx, hand_landmarks) in \
                enumerate(results_hand.multi_hand_landmarks):
                color = (0xFF, 0, 0)

                center_coordinates1 = \
                    (hand_landmarks.landmark[drawSpecific.HandLandmark.THUMB_TIP].x
                     * image_width,
                     hand_landmarks.landmark[drawSpecific.HandLandmark.THUMB_TIP].y
                     * image_height)
                center_coordinates2 = \
                    (hand_landmarks.landmark[drawSpecific.HandLandmark.INDEX_FINGER_TIP].x
                     * image_width,
                     hand_landmarks.landmark[drawSpecific.HandLandmark.INDEX_FINGER_TIP].y
                     * image_height)
                center_coordinates3 = \
                    (hand_landmarks.landmark[drawSpecific.HandLandmark.MIDDLE_FINGER_TIP].x
                     * image_width,
                     hand_landmarks.landmark[drawSpecific.HandLandmark.MIDDLE_FINGER_TIP].y
                     * image_height)
                center_coordinates4 = \
                    (hand_landmarks.landmark[drawSpecific.HandLandmark.RING_FINGER_TIP].x
                     * image_width,
                     hand_landmarks.landmark[drawSpecific.HandLandmark.RING_FINGER_TIP].y
                     * image_height)
                center_coordinates5 = \
                    (hand_landmarks.landmark[drawSpecific.HandLandmark.PINKY_TIP].x
                     * image_width,
                     hand_landmarks.landmark[drawSpecific.HandLandmark.PINKY_TIP].y
                     * image_height)

                img2 = cv2.imread("Rafath Auvee.png")
                img2 = cv2.resize(img2, (100,100))


                cv2.circle(image, (int(center_coordinates1[0]),
                           int(center_coordinates1[1])), 15, color, 5)
                cv2.circle(image, (int(center_coordinates2[0]),
                           int(center_coordinates2[1])), 15, color, 5)
                cv2.circle(image, (int(center_coordinates3[0]),
                           int(center_coordinates3[1])), 15, color, 5)
                cv2.circle(image, (int(center_coordinates4[0]),
                           int(center_coordinates4[1])), 15, color, 5)
                cv2.circle(image, (int(center_coordinates5[0]),
                           int(center_coordinates5[1])), 15, color, 5)


        cv2.imshow('Nail Tracking', imgResult)
        if cv2.waitKey(10) & 0xFF == ord('q'):
            break

    hands.close()
    cap.release()


main()

The output I want is something like this enter image description here

These images can be imported manually (within the circle).

P.S: Images isn't loading so I uploading this in imagebb

The detected image : https://ibb.co/5FNT70F

Output I expected: https://ibb.co/PF4n9kY

Auvee
  • 95
  • 2
  • 15
  • Where is your static image that you want to show inside the circles? – fmw42 Oct 11 '22 at 17:44
  • image is stored locally and I am getting the image by "imread". I'm not shown that in my code. – Auvee Oct 11 '22 at 18:23
  • 2
    [mre] is required. emphasis on *minimal*. none of that code is relevant if your question boils down to "how do I overlay one transparent image onto another". https://stackoverflow.com/questions/40895785/using-opencv-to-overlay-transparent-image-onto-another-image – Christoph Rackwitz Oct 11 '22 at 19:34
  • But how can I implement this overlay in webcam – Auvee Oct 12 '22 at 05:09

0 Answers0