Spaces:
Runtime error
Runtime error
opencv 4.x, numpy 2 compatibility
Browse files- SiamMask/tools/test.py +7 -4
SiamMask/tools/test.py
CHANGED
@@ -273,7 +273,7 @@ def siamese_track(state, im, mask_enable=False, refine_enable=False, device='cpu
|
|
273 |
c = -a * bbox[0]
|
274 |
d = -b * bbox[1]
|
275 |
mapping = np.array([[a, 0, c],
|
276 |
-
[0, b, d]]).astype(
|
277 |
crop = cv2.warpAffine(image, mapping, (out_sz[0], out_sz[1]),
|
278 |
flags=cv2.INTER_LINEAR,
|
279 |
borderMode=cv2.BORDER_CONSTANT,
|
@@ -289,10 +289,13 @@ def siamese_track(state, im, mask_enable=False, refine_enable=False, device='cpu
|
|
289 |
mask_in_img = crop_back(mask, back_box, (state['im_w'], state['im_h']))
|
290 |
|
291 |
target_mask = (mask_in_img > p.seg_thr).astype(np.uint8)
|
292 |
-
|
293 |
-
|
|
|
|
|
294 |
else:
|
295 |
-
|
|
|
296 |
cnt_area = [cv2.contourArea(cnt) for cnt in contours]
|
297 |
if len(contours) != 0 and np.max(cnt_area) > 100:
|
298 |
contour = contours[np.argmax(cnt_area)] # use max area polygon
|
|
|
273 |
c = -a * bbox[0]
|
274 |
d = -b * bbox[1]
|
275 |
mapping = np.array([[a, 0, c],
|
276 |
+
[0, b, d]]).astype(float)
|
277 |
crop = cv2.warpAffine(image, mapping, (out_sz[0], out_sz[1]),
|
278 |
flags=cv2.INTER_LINEAR,
|
279 |
borderMode=cv2.BORDER_CONSTANT,
|
|
|
289 |
mask_in_img = crop_back(mask, back_box, (state['im_w'], state['im_h']))
|
290 |
|
291 |
target_mask = (mask_in_img > p.seg_thr).astype(np.uint8)
|
292 |
+
contours_result = cv2.findContours(target_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
|
293 |
+
if len(contours_result) == 3:
|
294 |
+
# OpenCV ≤3.x
|
295 |
+
_, contours, _ = contours_result
|
296 |
else:
|
297 |
+
# OpenCV ≥4.x
|
298 |
+
contours, _ = contours_result
|
299 |
cnt_area = [cv2.contourArea(cnt) for cnt in contours]
|
300 |
if len(contours) != 0 and np.max(cnt_area) > 100:
|
301 |
contour = contours[np.argmax(cnt_area)] # use max area polygon
|