from cvzone.PoseModule import PoseDetector
import cv2

ESC = 27

cap = cv2.VideoCapture(0)
ratio = cap.get(cv2.CAP_PROP_FRAME_WIDTH) / cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
WIDTH = 400
HEIGHT = int(WIDTH / ratio)

detector = PoseDetector()

while cap.isOpened():
    success, img = cap.read()
    img = cv2.resize(img, (WIDTH, HEIGHT)) 
    img = detector.findPose(img)
    lmList, bboxInfo = detector.findPosition(img, bboxWithHands = False)
    if bboxInfo:
        center = bboxInfo["center"]
        cv2.circle(img, center, 5, (255, 0, 255), cv2.FILLED)
    cv2.imshow('Image', img)

    if cv2.waitKey(1) == ESC:
        break
    
cap.release()
cv2.destroyAllWindows()