fix bug for not scaling bbox
Browse files- app.py +2 -1
- lib/utils/vis_utils.py +25 -0
app.py
CHANGED
|
@@ -14,7 +14,7 @@ from lib.core.config import cfg, update_config
|
|
| 14 |
from lib.models.model import HACO
|
| 15 |
from lib.utils.human_models import mano
|
| 16 |
from lib.utils.contact_utils import get_contact_thres
|
| 17 |
-
from lib.utils.vis_utils import ContactRenderer, draw_landmarks_on_image
|
| 18 |
from lib.utils.preprocessing import augmentation_contact
|
| 19 |
from lib.utils.demo_utils import remove_small_contact_components, run_wilor_hand_detector
|
| 20 |
|
|
@@ -89,6 +89,7 @@ def process_image(pil_img: Image.Image):
|
|
| 89 |
# detection_result = detector.detect(mp_image)
|
| 90 |
# _, right_hand_bbox = draw_landmarks_on_image(orig_img.copy(), detection_result)
|
| 91 |
right_hand_bbox = run_wilor_hand_detector(orig_img, wilor_detector)
|
|
|
|
| 92 |
|
| 93 |
if right_hand_bbox is None:
|
| 94 |
return None, "No hand detected."
|
|
|
|
| 14 |
from lib.models.model import HACO
|
| 15 |
from lib.utils.human_models import mano
|
| 16 |
from lib.utils.contact_utils import get_contact_thres
|
| 17 |
+
from lib.utils.vis_utils import ContactRenderer, draw_landmarks_on_image, draw_landmarks_on_image_simple
|
| 18 |
from lib.utils.preprocessing import augmentation_contact
|
| 19 |
from lib.utils.demo_utils import remove_small_contact_components, run_wilor_hand_detector
|
| 20 |
|
|
|
|
| 89 |
# detection_result = detector.detect(mp_image)
|
| 90 |
# _, right_hand_bbox = draw_landmarks_on_image(orig_img.copy(), detection_result)
|
| 91 |
right_hand_bbox = run_wilor_hand_detector(orig_img, wilor_detector)
|
| 92 |
+
_, right_hand_bbox = draw_landmarks_on_image_simple(orig_img.copy(), right_hand_bbox)
|
| 93 |
|
| 94 |
if right_hand_bbox is None:
|
| 95 |
return None, "No hand detected."
|
lib/utils/vis_utils.py
CHANGED
|
@@ -96,4 +96,29 @@ def draw_landmarks_on_image(rgb_image, detection_result):
|
|
| 96 |
cv2.putText(annotated_image, "Right Hand", (x_min, y_min - MARGIN),
|
| 97 |
cv2.FONT_HERSHEY_DUPLEX, FONT_SIZE, HANDEDNESS_TEXT_COLOR, FONT_THICKNESS, cv2.LINE_AA)
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
return annotated_image, right_hand_bbox
|
|
|
|
| 96 |
cv2.putText(annotated_image, "Right Hand", (x_min, y_min - MARGIN),
|
| 97 |
cv2.FONT_HERSHEY_DUPLEX, FONT_SIZE, HANDEDNESS_TEXT_COLOR, FONT_THICKNESS, cv2.LINE_AA)
|
| 98 |
|
| 99 |
+
return annotated_image, right_hand_bbox
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def draw_landmarks_on_image_simple(rgb_image, right_hand_bbox):
|
| 103 |
+
# Draw bbox and label
|
| 104 |
+
annotated_image = rgb_image.copy()[..., ::-1]
|
| 105 |
+
annotated_image = np.ascontiguousarray(annotated_image)
|
| 106 |
+
|
| 107 |
+
# Expand bbox
|
| 108 |
+
x_min, x_max = int(right_hand_bbox[0]), int(right_hand_bbox[0]+right_hand_bbox[2])
|
| 109 |
+
y_min, y_max = int(right_hand_bbox[1]), int(right_hand_bbox[1]+right_hand_bbox[3])
|
| 110 |
+
bb_c_x, bb_c_y = (x_min+x_max)/2, (y_min+y_max)/2
|
| 111 |
+
bb_width, bb_height = x_max-x_min, y_max-y_min
|
| 112 |
+
|
| 113 |
+
expand_ratio = cfg.DATASET.ho_big_bbox_expand_ratio
|
| 114 |
+
|
| 115 |
+
bb_width_expand, bb_height_expand = expand_ratio * bb_width, expand_ratio * bb_height
|
| 116 |
+
x_min_expand, y_min_expand = bb_c_x - 0.5 * bb_width_expand, bb_c_y - 0.5 * bb_height_expand
|
| 117 |
+
|
| 118 |
+
right_hand_bbox = [x_min_expand, y_min_expand, bb_width_expand, bb_height_expand]
|
| 119 |
+
|
| 120 |
+
x_min, y_min, x_max, y_max = int(right_hand_bbox[0]), int(right_hand_bbox[1]), int(right_hand_bbox[0]+right_hand_bbox[2]), int(right_hand_bbox[1]+right_hand_bbox[3])
|
| 121 |
+
cv2.rectangle(annotated_image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)
|
| 122 |
+
cv2.putText(annotated_image, "Right Hand", (x_min, y_min - MARGIN), cv2.FONT_HERSHEY_DUPLEX, FONT_SIZE, HANDEDNESS_TEXT_COLOR, FONT_THICKNESS, cv2.LINE_AA)
|
| 123 |
+
|
| 124 |
return annotated_image, right_hand_bbox
|