Skip to content

Instantly share code, notes, and snippets.

@rlewkowicz
Created September 26, 2019 23:33
Show Gist options
  • Save rlewkowicz/e772d4de8df5e7f34685f42002d97f56 to your computer and use it in GitHub Desktop.
Save rlewkowicz/e772d4de8df5e7f34685f42002d97f56 to your computer and use it in GitHub Desktop.
def LoadImages(self, image, img_size=416, half=False):
img_size = img_size
mode = 'images'
half = half # half precision fp16 images
cap = None
img0 = image # BGR
img, *_ = letterbox(img0, new_shape=img_size)
# Normalize RGB
img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB
img = np.ascontiguousarray(img, dtype=np.float16 if half else np.float32) # uint8 to fp16/fp32
img /= 255.0 # 0 - 255 to 0.0 - 1.0
# cv2.imwrite(path + '.letterbox.jpg', 255 * img.transpose((1, 2, 0))[:, :, ::-1]) # save letterbox image
return img, img0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment