swap cv2.INTER_AREA for cv2.INTER_LINEAR
This commit is contained in:
parent
b98ce11d3a
commit
6736d7d125
|
@ -240,7 +240,7 @@ class LoadStreams: # multiple IP or RTSP cameras
|
|||
raise StopIteration
|
||||
|
||||
# Letterbox
|
||||
img = [letterbox(x, new_shape=self.img_size, auto=self.rect, interp=cv2.INTER_LINEAR)[0] for x in img0]
|
||||
img = [letterbox(x, new_shape=self.img_size, auto=self.rect)[0] for x in img0]
|
||||
|
||||
# Stack
|
||||
img = np.stack(img, 0)
|
||||
|
@ -508,8 +508,7 @@ def load_image(self, index):
|
|||
h0, w0 = img.shape[:2] # orig hw
|
||||
r = self.img_size / max(h0, w0) # resize image to img_size
|
||||
if r < 1 or (self.augment and (r != 1)): # always resize down, only resize up if training with augmentation
|
||||
interp = cv2.INTER_LINEAR if self.augment else cv2.INTER_AREA # LINEAR for training, AREA for testing
|
||||
img = cv2.resize(img, (int(w0 * r), int(h0 * r)), interpolation=interp)
|
||||
img = cv2.resize(img, (int(w0 * r), int(h0 * r)), interpolation=cv2.INTER_LINEAR)
|
||||
return img, (h0, w0), img.shape[:2] # img, hw_original, hw_resized
|
||||
else:
|
||||
return self.imgs[index], self.img_hw0[index], self.img_hw[index] # img, hw_original, hw_resized
|
||||
|
@ -589,8 +588,7 @@ def load_mosaic(self, index):
|
|||
return img4, labels4
|
||||
|
||||
|
||||
def letterbox(img, new_shape=(416, 416), color=(114, 114, 114),
|
||||
auto=True, scaleFill=False, scaleup=True, interp=cv2.INTER_AREA):
|
||||
def letterbox(img, new_shape=(416, 416), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True):
|
||||
# Resize image to a 32-pixel-multiple rectangle https://github.com/ultralytics/yolov3/issues/232
|
||||
shape = img.shape[:2] # current shape [height, width]
|
||||
if isinstance(new_shape, int):
|
||||
|
@ -616,7 +614,7 @@ def letterbox(img, new_shape=(416, 416), color=(114, 114, 114),
|
|||
dh /= 2
|
||||
|
||||
if shape[::-1] != new_unpad: # resize
|
||||
img = cv2.resize(img, new_unpad, interpolation=interp) # INTER_AREA is better, INTER_LINEAR is faster
|
||||
img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)
|
||||
top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1))
|
||||
left, right = int(round(dw - 0.1)), int(round(dw + 0.1))
|
||||
img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border
|
||||
|
@ -651,9 +649,8 @@ def random_affine(img, targets=(), degrees=10, translate=.1, scale=.1, shear=10,
|
|||
|
||||
# Combined rotation matrix
|
||||
M = S @ T @ R # ORDER IS IMPORTANT HERE!!
|
||||
changed = (border != 0) or (M != np.eye(3)).any()
|
||||
if changed:
|
||||
img = cv2.warpAffine(img, M[:2], dsize=(width, height), flags=cv2.INTER_AREA, borderValue=(114, 114, 114))
|
||||
if (border != 0) or (M != np.eye(3)).any(): # image changed
|
||||
img = cv2.warpAffine(img, M[:2], dsize=(width, height), flags=cv2.INTER_LINEAR, borderValue=(114, 114, 114))
|
||||
|
||||
# Transform label coordinates
|
||||
n = len(targets)
|
||||
|
|
Loading…
Reference in New Issue