Update main.py
Browse files
main.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
|
|
|
|
|
| 1 |
import copy
|
| 2 |
import math
|
| 3 |
import argparse
|
| 4 |
|
| 5 |
-
import cv2
|
| 6 |
import numpy as np
|
| 7 |
import mediapipe as mp
|
| 8 |
|
|
@@ -51,9 +53,10 @@ def main():
|
|
| 51 |
|
| 52 |
rev_color = args.rev_color
|
| 53 |
|
| 54 |
-
cap =
|
| 55 |
-
cap.set(
|
| 56 |
-
cap.set(
|
|
|
|
| 57 |
|
| 58 |
mp_pose = mp.solutions.pose
|
| 59 |
pose = mp_pose.Pose(
|
|
@@ -64,14 +67,15 @@ def main():
|
|
| 64 |
)
|
| 65 |
|
| 66 |
cvFpsCalc = CvFpsCalc(buffer_len=10)
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
bg_color = (255, 255, 255)
|
| 75 |
|
| 76 |
while True:
|
| 77 |
display_fps = cvFpsCalc.get()
|
|
@@ -79,19 +83,17 @@ def main():
|
|
| 79 |
ret, image = cap.read()
|
| 80 |
if not ret:
|
| 81 |
break
|
| 82 |
-
image =
|
| 83 |
debug_image01 = copy.deepcopy(image)
|
| 84 |
debug_image02 = np.zeros((image.shape[0], image.shape[1], 3), np.uint8)
|
| 85 |
-
|
| 86 |
bg_color,
|
| 87 |
thickness=-1)
|
| 88 |
|
| 89 |
-
image =
|
| 90 |
results = pose.process(image)
|
| 91 |
|
| 92 |
-
|
| 93 |
if results.pose_landmarks is not None:
|
| 94 |
-
|
| 95 |
debug_image01 = draw_landmarks(
|
| 96 |
debug_image01,
|
| 97 |
results.pose_landmarks,
|
|
@@ -103,22 +105,20 @@ def main():
|
|
| 103 |
bg_color=bg_color,
|
| 104 |
)
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
| 112 |
-
key =
|
| 113 |
-
if key == 27:
|
| 114 |
break
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
cv.imshow('Tokyo2020 Pictogram', debug_image02)
|
| 119 |
|
| 120 |
cap.release()
|
| 121 |
-
|
| 122 |
|
| 123 |
|
| 124 |
def draw_stick_figure(
|
|
@@ -130,7 +130,6 @@ def draw_stick_figure(
|
|
| 130 |
):
|
| 131 |
image_width, image_height = image.shape[1], image.shape[0]
|
| 132 |
|
| 133 |
-
|
| 134 |
landmark_point = []
|
| 135 |
for index, landmark in enumerate(landmarks.landmark):
|
| 136 |
landmark_x = min(int(landmark.x * image_width), image_width - 1)
|
|
@@ -139,7 +138,6 @@ def draw_stick_figure(
|
|
| 139 |
landmark_point.append(
|
| 140 |
[index, landmark.visibility, (landmark_x, landmark_y), landmark_z])
|
| 141 |
|
| 142 |
-
|
| 143 |
right_leg = landmark_point[23]
|
| 144 |
left_leg = landmark_point[24]
|
| 145 |
leg_x = int((right_leg[2][0] + left_leg[2][0]) / 2)
|
|
@@ -148,12 +146,10 @@ def draw_stick_figure(
|
|
| 148 |
landmark_point[23][2] = (leg_x, leg_y)
|
| 149 |
landmark_point[24][2] = (leg_x, leg_y)
|
| 150 |
|
| 151 |
-
|
| 152 |
sorted_landmark_point = sorted(landmark_point,
|
| 153 |
reverse=True,
|
| 154 |
key=lambda x: x[3])
|
| 155 |
|
| 156 |
-
|
| 157 |
(face_x, face_y), face_radius = min_enclosing_face_circle(landmark_point)
|
| 158 |
|
| 159 |
face_x = int(face_x)
|
|
@@ -164,21 +160,20 @@ def draw_stick_figure(
|
|
| 164 |
stick_radius02 = int(stick_radius01 * (3 / 4))
|
| 165 |
stick_radius03 = int(stick_radius02 * (3 / 4))
|
| 166 |
|
| 167 |
-
|
| 168 |
draw_list = [
|
| 169 |
-
11,
|
| 170 |
-
12,
|
| 171 |
-
23,
|
| 172 |
-
24,
|
| 173 |
]
|
| 174 |
|
| 175 |
|
| 176 |
-
|
| 177 |
bg_color,
|
| 178 |
thickness=-1)
|
| 179 |
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
|
| 184 |
for landmark_info in sorted_landmark_point:
|
|
@@ -224,7 +219,7 @@ def min_enclosing_face_circle(landmark_point):
|
|
| 224 |
]
|
| 225 |
landmark_array = np.append(landmark_array, np_landmark_point, axis=0)
|
| 226 |
|
| 227 |
-
center, radius =
|
| 228 |
|
| 229 |
return center, radius
|
| 230 |
|
|
@@ -238,8 +233,8 @@ def draw_stick(
|
|
| 238 |
color=(100, 33, 3),
|
| 239 |
bg_color=(255, 255, 255),
|
| 240 |
):
|
| 241 |
-
|
| 242 |
-
|
| 243 |
|
| 244 |
draw_list = []
|
| 245 |
for index in range(2):
|
|
@@ -257,7 +252,7 @@ def draw_stick(
|
|
| 257 |
draw_list.append([point_x, point_y])
|
| 258 |
|
| 259 |
points = np.array((draw_list[0], draw_list[1], draw_list[3], draw_list[2]))
|
| 260 |
-
|
| 261 |
|
| 262 |
return image
|
| 263 |
|
|
@@ -265,7 +260,7 @@ def draw_stick(
|
|
| 265 |
def draw_landmarks(
|
| 266 |
image,
|
| 267 |
landmarks,
|
| 268 |
-
|
| 269 |
visibility_th=0.5,
|
| 270 |
):
|
| 271 |
image_width, image_height = image.shape[1], image.shape[0]
|
|
@@ -281,207 +276,211 @@ def draw_landmarks(
|
|
| 281 |
if landmark.visibility < visibility_th:
|
| 282 |
continue
|
| 283 |
|
| 284 |
-
if index == 0:
|
| 285 |
-
|
| 286 |
-
if index == 1:
|
| 287 |
-
|
| 288 |
-
if index == 2:
|
| 289 |
-
|
| 290 |
-
if index == 3:
|
| 291 |
-
|
| 292 |
-
if index == 4:
|
| 293 |
-
|
| 294 |
-
if index == 5:
|
| 295 |
-
|
| 296 |
-
if index == 6:
|
| 297 |
-
|
| 298 |
-
if index == 7:
|
| 299 |
-
|
| 300 |
-
if index == 8:
|
| 301 |
-
|
| 302 |
-
if index == 9:
|
| 303 |
-
|
| 304 |
-
if index == 10:
|
| 305 |
-
|
| 306 |
-
if index == 11:
|
| 307 |
-
|
| 308 |
-
if index == 12:
|
| 309 |
-
|
| 310 |
-
if index == 13:
|
| 311 |
-
|
| 312 |
-
if index == 14:
|
| 313 |
-
|
| 314 |
-
if index == 15:
|
| 315 |
-
|
| 316 |
-
if index == 16:
|
| 317 |
-
|
| 318 |
-
if index == 17:
|
| 319 |
-
|
| 320 |
-
if index == 18:
|
| 321 |
-
|
| 322 |
-
if index == 19:
|
| 323 |
-
|
| 324 |
-
if index == 20:
|
| 325 |
-
|
| 326 |
-
if index == 21:
|
| 327 |
-
|
| 328 |
-
if index == 22:
|
| 329 |
-
|
| 330 |
-
if index == 23:
|
| 331 |
-
|
| 332 |
-
if index == 24:
|
| 333 |
-
|
| 334 |
-
if index == 25:
|
| 335 |
-
|
| 336 |
-
if index == 26:
|
| 337 |
-
|
| 338 |
-
if index == 27:
|
| 339 |
-
|
| 340 |
-
if index == 28:
|
| 341 |
-
|
| 342 |
-
if index == 29:
|
| 343 |
-
|
| 344 |
-
if index == 30:
|
| 345 |
-
|
| 346 |
-
if index == 31:
|
| 347 |
-
|
| 348 |
-
if index == 32:
|
| 349 |
-
|
| 350 |
|
| 351 |
# if not upper_body_only:
|
| 352 |
if True:
|
| 353 |
-
|
| 354 |
(landmark_x - 10, landmark_y - 10),
|
| 355 |
-
|
| 356 |
-
|
|
|
|
| 357 |
|
| 358 |
if landmark_point[1][0] > visibility_th and landmark_point[2][
|
| 359 |
0] > visibility_th:
|
| 360 |
-
|
| 361 |
(0, 255, 0), 2)
|
| 362 |
if landmark_point[2][0] > visibility_th and landmark_point[3][
|
| 363 |
0] > visibility_th:
|
| 364 |
-
|
| 365 |
(0, 255, 0), 2)
|
| 366 |
|
|
|
|
| 367 |
if landmark_point[4][0] > visibility_th and landmark_point[5][
|
| 368 |
0] > visibility_th:
|
| 369 |
-
|
| 370 |
(0, 255, 0), 2)
|
| 371 |
if landmark_point[5][0] > visibility_th and landmark_point[6][
|
| 372 |
0] > visibility_th:
|
| 373 |
-
|
| 374 |
(0, 255, 0), 2)
|
| 375 |
|
|
|
|
| 376 |
if landmark_point[9][0] > visibility_th and landmark_point[10][
|
| 377 |
0] > visibility_th:
|
| 378 |
-
|
| 379 |
(0, 255, 0), 2)
|
| 380 |
|
|
|
|
| 381 |
if landmark_point[11][0] > visibility_th and landmark_point[12][
|
| 382 |
0] > visibility_th:
|
| 383 |
-
|
| 384 |
(0, 255, 0), 2)
|
| 385 |
|
| 386 |
if landmark_point[11][0] > visibility_th and landmark_point[13][
|
| 387 |
0] > visibility_th:
|
| 388 |
-
|
| 389 |
(0, 255, 0), 2)
|
| 390 |
if landmark_point[13][0] > visibility_th and landmark_point[15][
|
| 391 |
0] > visibility_th:
|
| 392 |
-
|
| 393 |
(0, 255, 0), 2)
|
| 394 |
|
| 395 |
if landmark_point[12][0] > visibility_th and landmark_point[14][
|
| 396 |
0] > visibility_th:
|
| 397 |
-
|
| 398 |
(0, 255, 0), 2)
|
| 399 |
if landmark_point[14][0] > visibility_th and landmark_point[16][
|
| 400 |
0] > visibility_th:
|
| 401 |
-
|
| 402 |
(0, 255, 0), 2)
|
| 403 |
|
| 404 |
if landmark_point[15][0] > visibility_th and landmark_point[17][
|
| 405 |
0] > visibility_th:
|
| 406 |
-
|
| 407 |
(0, 255, 0), 2)
|
| 408 |
if landmark_point[17][0] > visibility_th and landmark_point[19][
|
| 409 |
0] > visibility_th:
|
| 410 |
-
|
| 411 |
(0, 255, 0), 2)
|
| 412 |
if landmark_point[19][0] > visibility_th and landmark_point[21][
|
| 413 |
0] > visibility_th:
|
| 414 |
-
|
| 415 |
(0, 255, 0), 2)
|
| 416 |
if landmark_point[21][0] > visibility_th and landmark_point[15][
|
| 417 |
0] > visibility_th:
|
| 418 |
-
|
| 419 |
(0, 255, 0), 2)
|
| 420 |
|
| 421 |
if landmark_point[16][0] > visibility_th and landmark_point[18][
|
| 422 |
0] > visibility_th:
|
| 423 |
-
|
| 424 |
(0, 255, 0), 2)
|
| 425 |
if landmark_point[18][0] > visibility_th and landmark_point[20][
|
| 426 |
0] > visibility_th:
|
| 427 |
-
|
| 428 |
(0, 255, 0), 2)
|
| 429 |
if landmark_point[20][0] > visibility_th and landmark_point[22][
|
| 430 |
0] > visibility_th:
|
| 431 |
-
|
| 432 |
(0, 255, 0), 2)
|
| 433 |
if landmark_point[22][0] > visibility_th and landmark_point[16][
|
| 434 |
0] > visibility_th:
|
| 435 |
-
|
| 436 |
(0, 255, 0), 2)
|
| 437 |
|
| 438 |
if landmark_point[11][0] > visibility_th and landmark_point[23][
|
| 439 |
0] > visibility_th:
|
| 440 |
-
|
| 441 |
(0, 255, 0), 2)
|
| 442 |
if landmark_point[12][0] > visibility_th and landmark_point[24][
|
| 443 |
0] > visibility_th:
|
| 444 |
-
|
| 445 |
(0, 255, 0), 2)
|
| 446 |
if landmark_point[23][0] > visibility_th and landmark_point[24][
|
| 447 |
0] > visibility_th:
|
| 448 |
-
|
| 449 |
(0, 255, 0), 2)
|
| 450 |
|
| 451 |
if len(landmark_point) > 25:
|
| 452 |
if landmark_point[23][0] > visibility_th and landmark_point[25][
|
| 453 |
0] > visibility_th:
|
| 454 |
-
|
| 455 |
(0, 255, 0), 2)
|
| 456 |
if landmark_point[25][0] > visibility_th and landmark_point[27][
|
| 457 |
0] > visibility_th:
|
| 458 |
-
|
| 459 |
(0, 255, 0), 2)
|
| 460 |
if landmark_point[27][0] > visibility_th and landmark_point[29][
|
| 461 |
0] > visibility_th:
|
| 462 |
-
|
| 463 |
(0, 255, 0), 2)
|
| 464 |
if landmark_point[29][0] > visibility_th and landmark_point[31][
|
| 465 |
0] > visibility_th:
|
| 466 |
-
|
| 467 |
(0, 255, 0), 2)
|
| 468 |
|
| 469 |
|
| 470 |
if landmark_point[24][0] > visibility_th and landmark_point[26][
|
| 471 |
0] > visibility_th:
|
| 472 |
-
|
| 473 |
(0, 255, 0), 2)
|
| 474 |
if landmark_point[26][0] > visibility_th and landmark_point[28][
|
| 475 |
0] > visibility_th:
|
| 476 |
-
|
| 477 |
(0, 255, 0), 2)
|
| 478 |
if landmark_point[28][0] > visibility_th and landmark_point[30][
|
| 479 |
0] > visibility_th:
|
| 480 |
-
|
| 481 |
(0, 255, 0), 2)
|
| 482 |
if landmark_point[30][0] > visibility_th and landmark_point[32][
|
| 483 |
0] > visibility_th:
|
| 484 |
-
|
| 485 |
(0, 255, 0), 2)
|
| 486 |
return image
|
| 487 |
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
import copy
|
| 4 |
import math
|
| 5 |
import argparse
|
| 6 |
|
| 7 |
+
import cv2
|
| 8 |
import numpy as np
|
| 9 |
import mediapipe as mp
|
| 10 |
|
|
|
|
| 53 |
|
| 54 |
rev_color = args.rev_color
|
| 55 |
|
| 56 |
+
cap = cv2.VideoCapture(cap_device)
|
| 57 |
+
cap.set(cv2.CAP_PROP_FRAME_WIDTH, cap_width)
|
| 58 |
+
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, cap_height)
|
| 59 |
+
|
| 60 |
|
| 61 |
mp_pose = mp.solutions.pose
|
| 62 |
pose = mp_pose.Pose(
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
cvFpsCalc = CvFpsCalc(buffer_len=10)
|
| 70 |
+
color = (100, 33, 3)
|
| 71 |
+
bg_color = (255, 255, 255)
|
| 72 |
|
| 73 |
+
# if rev_color:
|
| 74 |
+
# color = (255, 255, 255)
|
| 75 |
+
# bg_color = (100, 33, 3)
|
| 76 |
+
# else:
|
| 77 |
+
# color = (100, 33, 3)
|
| 78 |
+
# bg_color = (255, 255, 255)
|
|
|
|
| 79 |
|
| 80 |
while True:
|
| 81 |
display_fps = cvFpsCalc.get()
|
|
|
|
| 83 |
ret, image = cap.read()
|
| 84 |
if not ret:
|
| 85 |
break
|
| 86 |
+
image = cv2.flip(image, 1)
|
| 87 |
debug_image01 = copy.deepcopy(image)
|
| 88 |
debug_image02 = np.zeros((image.shape[0], image.shape[1], 3), np.uint8)
|
| 89 |
+
cv2.rectangle(debug_image02, (0, 0), (image.shape[1], image.shape[0]),
|
| 90 |
bg_color,
|
| 91 |
thickness=-1)
|
| 92 |
|
| 93 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 94 |
results = pose.process(image)
|
| 95 |
|
|
|
|
| 96 |
if results.pose_landmarks is not None:
|
|
|
|
| 97 |
debug_image01 = draw_landmarks(
|
| 98 |
debug_image01,
|
| 99 |
results.pose_landmarks,
|
|
|
|
| 105 |
bg_color=bg_color,
|
| 106 |
)
|
| 107 |
|
| 108 |
+
cv2.putText(debug_image01, "FPS:" + str(display_fps), (10, 30),
|
| 109 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2, cv2.LINE_AA)
|
| 110 |
+
cv2.putText(debug_image02, "FPS:" + str(display_fps), (10, 30),
|
| 111 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1.0, color, 2, cv2.LINE_AA)
|
| 112 |
|
| 113 |
+
key = cv2.waitKey(1)
|
| 114 |
+
if key == 27:
|
|
|
|
| 115 |
break
|
| 116 |
|
| 117 |
+
cv2.imshow('Debug', debug_image01)
|
| 118 |
+
cv2.imshow('Pictogram', debug_image02)
|
|
|
|
| 119 |
|
| 120 |
cap.release()
|
| 121 |
+
cv2.destroyAllWindows()
|
| 122 |
|
| 123 |
|
| 124 |
def draw_stick_figure(
|
|
|
|
| 130 |
):
|
| 131 |
image_width, image_height = image.shape[1], image.shape[0]
|
| 132 |
|
|
|
|
| 133 |
landmark_point = []
|
| 134 |
for index, landmark in enumerate(landmarks.landmark):
|
| 135 |
landmark_x = min(int(landmark.x * image_width), image_width - 1)
|
|
|
|
| 138 |
landmark_point.append(
|
| 139 |
[index, landmark.visibility, (landmark_x, landmark_y), landmark_z])
|
| 140 |
|
|
|
|
| 141 |
right_leg = landmark_point[23]
|
| 142 |
left_leg = landmark_point[24]
|
| 143 |
leg_x = int((right_leg[2][0] + left_leg[2][0]) / 2)
|
|
|
|
| 146 |
landmark_point[23][2] = (leg_x, leg_y)
|
| 147 |
landmark_point[24][2] = (leg_x, leg_y)
|
| 148 |
|
|
|
|
| 149 |
sorted_landmark_point = sorted(landmark_point,
|
| 150 |
reverse=True,
|
| 151 |
key=lambda x: x[3])
|
| 152 |
|
|
|
|
| 153 |
(face_x, face_y), face_radius = min_enclosing_face_circle(landmark_point)
|
| 154 |
|
| 155 |
face_x = int(face_x)
|
|
|
|
| 160 |
stick_radius02 = int(stick_radius01 * (3 / 4))
|
| 161 |
stick_radius03 = int(stick_radius02 * (3 / 4))
|
| 162 |
|
|
|
|
| 163 |
draw_list = [
|
| 164 |
+
11,
|
| 165 |
+
12,
|
| 166 |
+
23,
|
| 167 |
+
24,
|
| 168 |
]
|
| 169 |
|
| 170 |
|
| 171 |
+
cv2.rectangle(image, (0, 0), (image_width, image_height),
|
| 172 |
bg_color,
|
| 173 |
thickness=-1)
|
| 174 |
|
| 175 |
|
| 176 |
+
cv2.circle(image, (face_x, face_y), face_radius, color, -1)
|
| 177 |
|
| 178 |
|
| 179 |
for landmark_info in sorted_landmark_point:
|
|
|
|
| 219 |
]
|
| 220 |
landmark_array = np.append(landmark_array, np_landmark_point, axis=0)
|
| 221 |
|
| 222 |
+
center, radius = cv2.minEnclosingCircle(points=landmark_array)
|
| 223 |
|
| 224 |
return center, radius
|
| 225 |
|
|
|
|
| 233 |
color=(100, 33, 3),
|
| 234 |
bg_color=(255, 255, 255),
|
| 235 |
):
|
| 236 |
+
cv2.circle(image, point01, point01_radius, color, -1)
|
| 237 |
+
cv2.circle(image, point02, point02_radius, color, -1)
|
| 238 |
|
| 239 |
draw_list = []
|
| 240 |
for index in range(2):
|
|
|
|
| 252 |
draw_list.append([point_x, point_y])
|
| 253 |
|
| 254 |
points = np.array((draw_list[0], draw_list[1], draw_list[3], draw_list[2]))
|
| 255 |
+
cv2.fillConvexPoly(image, points=points, color=color)
|
| 256 |
|
| 257 |
return image
|
| 258 |
|
|
|
|
| 260 |
def draw_landmarks(
|
| 261 |
image,
|
| 262 |
landmarks,
|
| 263 |
+
|
| 264 |
visibility_th=0.5,
|
| 265 |
):
|
| 266 |
image_width, image_height = image.shape[1], image.shape[0]
|
|
|
|
| 276 |
if landmark.visibility < visibility_th:
|
| 277 |
continue
|
| 278 |
|
| 279 |
+
if index == 0:
|
| 280 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 281 |
+
if index == 1:
|
| 282 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 283 |
+
if index == 2:
|
| 284 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 285 |
+
if index == 3:
|
| 286 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 287 |
+
if index == 4:
|
| 288 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 289 |
+
if index == 5:
|
| 290 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 291 |
+
if index == 6:
|
| 292 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 293 |
+
if index == 7:
|
| 294 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 295 |
+
if index == 8:
|
| 296 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 297 |
+
if index == 9:
|
| 298 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 299 |
+
if index == 10:
|
| 300 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 301 |
+
if index == 11:
|
| 302 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 303 |
+
if index == 12:
|
| 304 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 305 |
+
if index == 13:
|
| 306 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 307 |
+
if index == 14:
|
| 308 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 309 |
+
if index == 15:
|
| 310 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 311 |
+
if index == 16:
|
| 312 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 313 |
+
if index == 17:
|
| 314 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 315 |
+
if index == 18:
|
| 316 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 317 |
+
if index == 19:
|
| 318 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 319 |
+
if index == 20:
|
| 320 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 321 |
+
if index == 21:
|
| 322 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 323 |
+
if index == 22:
|
| 324 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 325 |
+
if index == 23:
|
| 326 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 327 |
+
if index == 24:
|
| 328 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 329 |
+
if index == 25:
|
| 330 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 331 |
+
if index == 26:
|
| 332 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 333 |
+
if index == 27:
|
| 334 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 335 |
+
if index == 28:
|
| 336 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 337 |
+
if index == 29:
|
| 338 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 339 |
+
if index == 30:
|
| 340 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 341 |
+
if index == 31:
|
| 342 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 343 |
+
if index == 32:
|
| 344 |
+
cv2.circle(image, (landmark_x, landmark_y), 5, (0, 255, 0), 2)
|
| 345 |
|
| 346 |
# if not upper_body_only:
|
| 347 |
if True:
|
| 348 |
+
cv2.putText(image, "z:" + str(round(landmark_z, 3)),
|
| 349 |
(landmark_x - 10, landmark_y - 10),
|
| 350 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1,
|
| 351 |
+
cv2.LINE_AA)
|
| 352 |
+
|
| 353 |
|
| 354 |
if landmark_point[1][0] > visibility_th and landmark_point[2][
|
| 355 |
0] > visibility_th:
|
| 356 |
+
cv2.line(image, landmark_point[1][1], landmark_point[2][1],
|
| 357 |
(0, 255, 0), 2)
|
| 358 |
if landmark_point[2][0] > visibility_th and landmark_point[3][
|
| 359 |
0] > visibility_th:
|
| 360 |
+
cv2.line(image, landmark_point[2][1], landmark_point[3][1],
|
| 361 |
(0, 255, 0), 2)
|
| 362 |
|
| 363 |
+
|
| 364 |
if landmark_point[4][0] > visibility_th and landmark_point[5][
|
| 365 |
0] > visibility_th:
|
| 366 |
+
cv2.line(image, landmark_point[4][1], landmark_point[5][1],
|
| 367 |
(0, 255, 0), 2)
|
| 368 |
if landmark_point[5][0] > visibility_th and landmark_point[6][
|
| 369 |
0] > visibility_th:
|
| 370 |
+
cv2.line(image, landmark_point[5][1], landmark_point[6][1],
|
| 371 |
(0, 255, 0), 2)
|
| 372 |
|
| 373 |
+
|
| 374 |
if landmark_point[9][0] > visibility_th and landmark_point[10][
|
| 375 |
0] > visibility_th:
|
| 376 |
+
cv2.line(image, landmark_point[9][1], landmark_point[10][1],
|
| 377 |
(0, 255, 0), 2)
|
| 378 |
|
| 379 |
+
|
| 380 |
if landmark_point[11][0] > visibility_th and landmark_point[12][
|
| 381 |
0] > visibility_th:
|
| 382 |
+
cv2.line(image, landmark_point[11][1], landmark_point[12][1],
|
| 383 |
(0, 255, 0), 2)
|
| 384 |
|
| 385 |
if landmark_point[11][0] > visibility_th and landmark_point[13][
|
| 386 |
0] > visibility_th:
|
| 387 |
+
cv2.line(image, landmark_point[11][1], landmark_point[13][1],
|
| 388 |
(0, 255, 0), 2)
|
| 389 |
if landmark_point[13][0] > visibility_th and landmark_point[15][
|
| 390 |
0] > visibility_th:
|
| 391 |
+
cv2.line(image, landmark_point[13][1], landmark_point[15][1],
|
| 392 |
(0, 255, 0), 2)
|
| 393 |
|
| 394 |
if landmark_point[12][0] > visibility_th and landmark_point[14][
|
| 395 |
0] > visibility_th:
|
| 396 |
+
cv2.line(image, landmark_point[12][1], landmark_point[14][1],
|
| 397 |
(0, 255, 0), 2)
|
| 398 |
if landmark_point[14][0] > visibility_th and landmark_point[16][
|
| 399 |
0] > visibility_th:
|
| 400 |
+
cv2.line(image, landmark_point[14][1], landmark_point[16][1],
|
| 401 |
(0, 255, 0), 2)
|
| 402 |
|
| 403 |
if landmark_point[15][0] > visibility_th and landmark_point[17][
|
| 404 |
0] > visibility_th:
|
| 405 |
+
cv2.line(image, landmark_point[15][1], landmark_point[17][1],
|
| 406 |
(0, 255, 0), 2)
|
| 407 |
if landmark_point[17][0] > visibility_th and landmark_point[19][
|
| 408 |
0] > visibility_th:
|
| 409 |
+
cv2.line(image, landmark_point[17][1], landmark_point[19][1],
|
| 410 |
(0, 255, 0), 2)
|
| 411 |
if landmark_point[19][0] > visibility_th and landmark_point[21][
|
| 412 |
0] > visibility_th:
|
| 413 |
+
cv2.line(image, landmark_point[19][1], landmark_point[21][1],
|
| 414 |
(0, 255, 0), 2)
|
| 415 |
if landmark_point[21][0] > visibility_th and landmark_point[15][
|
| 416 |
0] > visibility_th:
|
| 417 |
+
cv2.line(image, landmark_point[21][1], landmark_point[15][1],
|
| 418 |
(0, 255, 0), 2)
|
| 419 |
|
| 420 |
if landmark_point[16][0] > visibility_th and landmark_point[18][
|
| 421 |
0] > visibility_th:
|
| 422 |
+
cv2.line(image, landmark_point[16][1], landmark_point[18][1],
|
| 423 |
(0, 255, 0), 2)
|
| 424 |
if landmark_point[18][0] > visibility_th and landmark_point[20][
|
| 425 |
0] > visibility_th:
|
| 426 |
+
cv2.line(image, landmark_point[18][1], landmark_point[20][1],
|
| 427 |
(0, 255, 0), 2)
|
| 428 |
if landmark_point[20][0] > visibility_th and landmark_point[22][
|
| 429 |
0] > visibility_th:
|
| 430 |
+
cv2.line(image, landmark_point[20][1], landmark_point[22][1],
|
| 431 |
(0, 255, 0), 2)
|
| 432 |
if landmark_point[22][0] > visibility_th and landmark_point[16][
|
| 433 |
0] > visibility_th:
|
| 434 |
+
cv2.line(image, landmark_point[22][1], landmark_point[16][1],
|
| 435 |
(0, 255, 0), 2)
|
| 436 |
|
| 437 |
if landmark_point[11][0] > visibility_th and landmark_point[23][
|
| 438 |
0] > visibility_th:
|
| 439 |
+
cv2.line(image, landmark_point[11][1], landmark_point[23][1],
|
| 440 |
(0, 255, 0), 2)
|
| 441 |
if landmark_point[12][0] > visibility_th and landmark_point[24][
|
| 442 |
0] > visibility_th:
|
| 443 |
+
cv2.line(image, landmark_point[12][1], landmark_point[24][1],
|
| 444 |
(0, 255, 0), 2)
|
| 445 |
if landmark_point[23][0] > visibility_th and landmark_point[24][
|
| 446 |
0] > visibility_th:
|
| 447 |
+
cv2.line(image, landmark_point[23][1], landmark_point[24][1],
|
| 448 |
(0, 255, 0), 2)
|
| 449 |
|
| 450 |
if len(landmark_point) > 25:
|
| 451 |
if landmark_point[23][0] > visibility_th and landmark_point[25][
|
| 452 |
0] > visibility_th:
|
| 453 |
+
cv2.line(image, landmark_point[23][1], landmark_point[25][1],
|
| 454 |
(0, 255, 0), 2)
|
| 455 |
if landmark_point[25][0] > visibility_th and landmark_point[27][
|
| 456 |
0] > visibility_th:
|
| 457 |
+
cv2.line(image, landmark_point[25][1], landmark_point[27][1],
|
| 458 |
(0, 255, 0), 2)
|
| 459 |
if landmark_point[27][0] > visibility_th and landmark_point[29][
|
| 460 |
0] > visibility_th:
|
| 461 |
+
cv2.line(image, landmark_point[27][1], landmark_point[29][1],
|
| 462 |
(0, 255, 0), 2)
|
| 463 |
if landmark_point[29][0] > visibility_th and landmark_point[31][
|
| 464 |
0] > visibility_th:
|
| 465 |
+
cv2.line(image, landmark_point[29][1], landmark_point[31][1],
|
| 466 |
(0, 255, 0), 2)
|
| 467 |
|
| 468 |
|
| 469 |
if landmark_point[24][0] > visibility_th and landmark_point[26][
|
| 470 |
0] > visibility_th:
|
| 471 |
+
cv2.line(image, landmark_point[24][1], landmark_point[26][1],
|
| 472 |
(0, 255, 0), 2)
|
| 473 |
if landmark_point[26][0] > visibility_th and landmark_point[28][
|
| 474 |
0] > visibility_th:
|
| 475 |
+
cv2.line(image, landmark_point[26][1], landmark_point[28][1],
|
| 476 |
(0, 255, 0), 2)
|
| 477 |
if landmark_point[28][0] > visibility_th and landmark_point[30][
|
| 478 |
0] > visibility_th:
|
| 479 |
+
cv2.line(image, landmark_point[28][1], landmark_point[30][1],
|
| 480 |
(0, 255, 0), 2)
|
| 481 |
if landmark_point[30][0] > visibility_th and landmark_point[32][
|
| 482 |
0] > visibility_th:
|
| 483 |
+
cv2.line(image, landmark_point[30][1], landmark_point[32][1],
|
| 484 |
(0, 255, 0), 2)
|
| 485 |
return image
|
| 486 |
|