Skip to content
Advertisement

create a rectangle around all the points returned from mediapipe hand landmark detection just like cv2.boundingrect does

I am using following code to detect hand landmarks using mediapipe

JavaScript

I just want a rectangle around all the points returned by the detector Please tell if there is any way to do so built in mediapipe or using opencv

Advertisement

Answer

  1. Before the while loop, determine the width and height each frame will be:
JavaScript
  1. For each landLM detected, define the initial variables for smallest x and y coordinates, and the largest x and y coordinates. The first two variables will later act as the starting point of the rectangle, and the last two variables will later act as the last point of the rectangle:
JavaScript
  1. Loop through the handLM variable, and finding the x and y coordinates of each point of the hand:
JavaScript
  1. Update the minimum and maximum x and y variables as new coordinates are being detected:
JavaScript
  1. Finally, draw the rectangle with the points:
JavaScript

Altogether:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement