from cvzone.PoseModule import PoseDetector
import cv2

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 = cv2.rotate(img, rotateCode = 1)
    img = cv2.flip(img, 1)

    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) == 27:
        break
    
cap.release()
cv2.destroyAllWindows()