Esempio n. 1
0
    w = xmax - xmin
    h = ymax - ymin
    rate = w / h
    return rate


img_path = "examples/Capture/video10_lb/video (10).avi_000006.641.jpg"
img_path = "examples/media//example.jpg"
estimator = BodyPoseEstimator(pretrained=True)
image_src = cv2.imread(img_path, cv2.IMREAD_ANYCOLOR)
keypoints = estimator(image_src)
print(keypoints)
image = image_src.copy()
w, h, v = image.shape
print(image.shape)
cv2.rectangle(image, (0, 0), (h, w), (255, 255, 255), -1)

image_dst = draw_body_connections(image, keypoints, thickness=2, alpha=0.7)
image_dst = draw_keypoints(image_dst, keypoints, radius=3, alpha=0.8)
#image_dst = draw_numbers(image_dst, keypoints[:, 0:14, :], alpha=0.9, thickness=1)
angle = get_angle(keypoints)
rate = get_rate(keypoints)
mykey = keypoints[0, 0:14, :]  # (14, 3)  =>   x, y, v
print(f"rate={rate:7.2f} , angle={angle:7.2f} ")

while True:
    cv2.imshow('Image Demo', image_dst)
    if cv2.waitKey(1) & 0xff == 27:  # exit if pressed `ESC`
        break
cv2.destroyAllWindows()
Esempio n. 2
0
 output_name = f"{os.path.dirname(video_fullpath).split(os.path.sep)[-1]}_{os.path.basename(video_fullpath)}"
 estimator = BodyPoseEstimator(pretrained=True)
 videoclip = cv2.VideoCapture(video_fullpath)
 count = 0
 while videoclip.isOpened():
     flag, frame = videoclip.read()
     if not flag:
         break
     count += 1
     try:
         keypoints = estimator(frame)
         frame = draw_body_connections(frame,
                                       keypoints,
                                       thickness=2,
                                       alpha=0.7)
         frame = draw_keypoints(frame, keypoints, radius=3, alpha=0.8)
         angle = get_angle(keypoints)
         rate = get_rate(keypoints)
         direct = get_direction(keypoints)
         data = get_keydata(output_name, count, keypoints, angle, rate,
                            direct)
         f.write(data)
         print(
             f"{output_name} No={count:4d}   rate={rate:7.2f}   angle={angle:7.2f}   direct={direct:3d}"
         )
         '''
         cv2.imshow('Video Demo', frame)
         if cv2.waitKey(1) & 0xff == 27: # exit if pressed `ESC`
             break
         '''
     except KeyboardInterrupt: