Skip to content

Commit db62c3a

Browse files
benhoffChris Lee-Messer
authored andcommitted
fix off by one error in mask rcnn (cvat-ai#801)
1 parent 83e0f79 commit db62c3a

File tree

1 file changed

+8
-8
lines changed
  • utils/open_model_zoo/mask_rcnn_inception_resnet_v2_atrous_coco

1 file changed

+8
-8
lines changed

utils/open_model_zoo/mask_rcnn_inception_resnet_v2_atrous_coco/interp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import cv2
3+
from skimage.measure import approximate_polygon, find_contours
34

45

56
MASK_THRESHOLD = .5
@@ -43,22 +44,21 @@ def segm_postprocess(box: list, raw_cls_mask, im_h, im_w, threshold):
4344
y = box[4] * height
4445
right = box[5] * width
4546
bottom = box[6] * height
46-
mask = masks[index][label]
47+
mask = masks[index][label - 1]
4748

4849
mask = segm_postprocess((x, y, right, bottom),
4950
mask,
5051
height,
5152
width,
5253
MASK_THRESHOLD)
5354

54-
contour, _ = cv2.findContours(mask,
55-
cv2.RETR_EXTERNAL,
56-
cv2.CHAIN_APPROX_TC89_KCOS)
55+
contours = find_contours(mask, MASK_THRESHOLD)
56+
contour = contours[0]
57+
contour = np.flip(contour, axis=1)
58+
contour = approximate_polygon(contour, tolerance=2.5)
59+
segmentation = contour.tolist()
5760

58-
contour = contour[0]
59-
contour = contour.tolist()
60-
contour = [x[0] for x in contour]
6161

6262
# NOTE: if you want to see the boxes, uncomment next line
6363
# results.add_box(x, y, right, bottom, label, frame_number)
64-
results.add_polygon(contour, label, frame_number)
64+
results.add_polygon(segmentation, label, frame_number)

0 commit comments

Comments
 (0)