in models/02_YoloV4/01_Pytorch/utils.py [0:0]
def preprocess_img(img, img_size=416):
'''
Preprocess an OpenCV raw image and prepare
it for the format expected by the network
'''
# img is a raw BGR cv2 image
h,w,c = img.shape
if h!=w: # make a square to keep the aspect ratio
cur_img_size = max(w,h)
img_ = np.zeros((cur_img_size,cur_img_size,c), dtype=np.uint8)
img_[0:h, 0:w] = img
img = img_
img = cv2.resize(img, (img_size, img_size))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = img.transpose(2,0,1).astype(np.float32) / 255.0
return img