6Morpheus6 commited on
Commit
7a2ae76
·
verified ·
1 Parent(s): 4e6f592

opencv 4.x, numpy 2 compatibility

Browse files
Files changed (1) hide show
  1. 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(np.float)
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
- if cv2.__version__[-5] == '4':
293
- contours, _ = cv2.findContours(target_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
 
 
294
  else:
295
- _, contours, _ = cv2.findContours(target_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
 
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