Skip to content

Commit 999ef2c

Browse files
committed
faster when alpha mask = 1
1 parent 2adf9a1 commit 999ef2c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

patched_yolo_infer/functions_extra.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,12 @@ def visualize_results(
355355
)
356356

357357
if fill_mask:
358-
color_mask = np.zeros_like(img)
359-
color_mask[mask_resized > 0] = color
360-
labeled_image = cv2.addWeighted(labeled_image, 1, color_mask, alpha, 0)
358+
if alpha == 1:
359+
cv2.fillPoly(labeled_image, pts=mask_contours, color=color)
360+
else:
361+
color_mask = np.zeros_like(img)
362+
color_mask[mask_resized > 0] = color
363+
labeled_image = cv2.addWeighted(labeled_image, 1, color_mask, alpha, 0)
361364

362365
cv2.drawContours(labeled_image, mask_contours, -1, color, thickness)
363366

@@ -366,7 +369,7 @@ def visualize_results(
366369
points = np.array(polygons[i].reshape((-1, 1, 2)), dtype=np.int32)
367370
cv2.drawContours(labeled_image, [points], -1, color, thickness)
368371
if fill_mask:
369-
cv2.fillPoly(labeled_image, pts=[points], color=(*color, alpha))
372+
cv2.fillPoly(labeled_image, pts=[points], color=color)
370373

371374
# Write class label
372375
if show_boxes:

0 commit comments

Comments
 (0)