Commit b0520936 authored by Yuxin Wu's avatar Yuxin Wu Committed by Facebook Github Bot

Call findContours in a compatible way (#119, #9) (#847)

Summary:
OpenCV 2, 3, 4 have different signatures for this function. Using [-2] is compatible with them.
Pull Request resolved: https://github.com/facebookresearch/Detectron/pull/847

Reviewed By: rbgirshick

Differential Revision: D14703716

Pulled By: ir413

fbshipit-source-id: 7329c5d45a0b0d2a3125198e6ac64bc79b42ff46
parent 5dcc556e
...@@ -104,8 +104,8 @@ def vis_mask(img, mask, col, alpha=0.4, show_border=True, border_thick=1): ...@@ -104,8 +104,8 @@ def vis_mask(img, mask, col, alpha=0.4, show_border=True, border_thick=1):
img[idx[0], idx[1], :] += alpha * col img[idx[0], idx[1], :] += alpha * col
if show_border: if show_border:
_, contours, _ = cv2.findContours( contours = cv2.findContours(
mask.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) mask.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)[-2]
cv2.drawContours(img, contours, -1, _WHITE, border_thick, cv2.LINE_AA) cv2.drawContours(img, contours, -1, _WHITE, border_thick, cv2.LINE_AA)
return img.astype(np.uint8) return img.astype(np.uint8)
...@@ -328,8 +328,8 @@ def vis_one_image( ...@@ -328,8 +328,8 @@ def vis_one_image(
img[:, :, c] = color_mask[c] img[:, :, c] = color_mask[c]
e = masks[:, :, i] e = masks[:, :, i]
_, contour, hier = cv2.findContours( contour = cv2.findContours(
e.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) e.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)[-2]
for c in contour: for c in contour:
polygon = Polygon( polygon = Polygon(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment