KevsRobots Learning Platform
By Kevin McAleer, 3 Minutes
Pose detection finds the position of a person’s body: their head, shoulders, elbows, hips, knees and feet. It’s used in fitness apps, motion capture and games. CVZone’s PoseDetector uses MediaPipe’s pose model, which finds 33 landmarks on the body.

Some useful landmark numbers:
| Landmark | Body part |
|---|---|
| 0 | Nose |
| 11, 12 | Left and right shoulder |
| 13, 14 | Left and right elbow |
| 15, 16 | Left and right wrist |
| 23, 24 | Left and right hip |
| 25, 26 | Left and right knee |
MediaPipe was installed in the first lesson, so you’re ready to go.
import cv2
from cvzone.PoseModule import PoseDetector
cap = cv2.VideoCapture(0)
detector = PoseDetector(detectionCon=0.5, trackCon=0.5)
while True:
success, img = cap.read()
if not success:
break
img = detector.findPose(img)
lmList, bboxInfo = detector.findPosition(img, draw=True, bboxWithHands=False)
if lmList:
# Mark the centre of the body
cv2.circle(img, bboxInfo["center"], 5, (255, 0, 255), cv2.FILLED)
# Distance from the left shoulder (11) to the left wrist (15)
length, img, info = detector.findDistance(lmList[11][0:2], lmList[15][0:2],
img=img, color=(255, 0, 0), scale=10)
# Angle at the left elbow: shoulder (11), elbow (13), wrist (15)
angle, img = detector.findAngle(lmList[11][0:2], lmList[13][0:2], lmList[15][0:2],
img=img, color=(0, 0, 255), scale=10)
# Is the elbow bent to about 50 degrees, give or take 10?
print(int(angle), detector.angleCheck(myAngle=angle, targetAngle=50, offset=10))
cv2.imshow("Pose Detection", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
detector.findPose(img) runs the pose model and draws the skeleton on the imagedetector.findPosition(img) returns lmList, a list of 33 [x, y, z] landmarks, and bboxInfo, the box around the body. lmList is empty when nobody is in viewlmList[11][0:2] takes just the x, y of landmark 11, the left shoulderfindDistance() measures the distance between two points in pixels and draws itfindAngle() measures the angle at the middle point. With shoulder, elbow and wrist, that’s how bent the elbow isangleCheck() returns True if the angle is within offset degrees of the targetWhich side is left?
Landmark 11 is the person’s own left shoulder. If you’re facing the camera, it appears on the right of the picture.
Quick quiz 1 of 2
Which three landmarks measure how bent the left elbow is?
Quick quiz 2 of 2
What does detector.angleCheck(myAngle=angle, targetAngle=90, offset=15) return when the angle is 100?
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments