Speed up preprocessing.
This commit is contained in:
@ -11,13 +11,10 @@ def letterbox(img: np.ndarray, target_size: Sequence[int], fill_value: int = 128
|
||||
|
||||
scale = min(tw / w, th / h)
|
||||
nw, nh = int(w * scale), int(h * scale)
|
||||
|
||||
resized_img = cv2.resize(img, (nw, nh))
|
||||
dx, dy = (tw - nw) // 2, (th - nh) // 2
|
||||
|
||||
canvas = np.full((th, tw, img.shape[2]), fill_value, dtype=img.dtype)
|
||||
|
||||
dx, dy = (tw - nw) // 2, (th - nh) // 2
|
||||
canvas[dy:dy + nh, dx:dx + nw, :] = resized_img
|
||||
canvas[dy:dy + nh, dx:dx + nw, :] = cv2.resize(img, (nw, nh))
|
||||
|
||||
return canvas, dx, dy, scale
|
||||
|
||||
|
||||
Reference in New Issue
Block a user