Skip to content

Instantly share code, notes, and snippets.

@doleron
Last active January 23, 2022 11:36
Show Gist options
  • Save doleron/97dae8573e23d24aa941dbb8be81961a to your computer and use it in GitHub Desktop.
Save doleron/97dae8573e23d24aa941dbb8be81961a to your computer and use it in GitHub Desktop.
python format input
def format_yolov5(source):
# put the image in square big enough
col, row, _ = source.shape
_max = max(col, row)
resized = np.zeros((_max, _max, 3), np.uint8)
resized[0:col, 0:row] = source
# resize to 640x640, normalize to [0,1[ and swap Red and Blue channels
result = cv2.dnn.blobFromImage(resized, 1/255.0, (640, 640), swapRB=True)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment