Last active
July 22, 2021 14:54
-
-
Save RishiRajak/2f83a1d4804eeb9868f1090a63272db1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getKeyPts(imgpath): | |
import cv2 | |
import mediapipe #uses RGB | |
import time | |
modelPose = mediapipe.solutions.pose | |
mpDraw = mediapipe.solutions.drawing_utils | |
pose = modelPose.Pose() | |
mp_holistic = mediapipe.solutions.holistic | |
#visit media pipe for landmark labels | |
#https://google.github.io/mediapipe/solutions/pose#static_image_mode | |
img = cv2.imread(imgpath) #path to ur video instead of 0 | |
frameRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB) | |
results = pose.process(frameRGB) | |
print(f"landmarks :{results.pose_landmarks}") | |
# print( | |
# f'Nose coordinates: (' | |
# f'{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].x * frame.shape[0]}, ' | |
# f'{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].y * frame.shape[1]})') | |
if results.pose_landmarks: | |
mpDraw.draw_landmarks(frame,results.pose_landmarks,modelPose.POSE_CONNECTIONS) | |
for id,keyPts in enumerate(results.pose_landmarks.landmark): | |
h,w,c = frame.shape | |
print(id,keyPts) | |
cx,cy = int(keyPts.x*w),int(keyPts.y*h) | |
cv2.circle(frame,(cx,cy),3,(255,0,255),-1) | |
cv2.imshow("ImageCapture",img) | |
k = cv2.waitKey(1) | |
if k & 0xff == ord("c"): #press c to close | |
break | |
else: | |
break | |
cap.release() | |
cv2.destroyAllWindows() | |
return results.pose_landmarks.landmark |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment