Speed up preprocessing.

This commit is contained in:
Daniel
2024-11-29 16:19:06 +01:00
parent 93d4611a91
commit 1b5e0c44e3
4 changed files with 24 additions and 21 deletions

View File

@ -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