def prep_im_for_blob(im, pixel_means, target_size, max_size):
 im = im.astype(np.float32, copy=False)
 im -= pixel_means
 im_shape = im.shape
 im_size_min = np.min(im_shape[0:2])
 im_size_max = np.max(im_shape[0:2])
 im_scale = (float(target_size) / float(im_size_min))
 if (np.round((im_scale * im_size_max)) > max_size):
  im_scale = (float(max_size) / float(im_size_max))
 im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR)
 return (im, im_scale)

def prep_im_for_blob ( im , pixel_means , target_size , max_size ) : im = im . astype ( np . float32 , copy = False ) im -= pixel_means im_shape = im . shape im_size_min = np . min ( im_shape [ 0 : 2 ] ) im_size_max = np . max ( im_shape [ 0 : 2 ] ) im_scale = ( float ( target_size ) / float ( im_size_min ) ) if ( np . round ( ( im_scale * im_size_max ) ) > max_size ) : im_scale = ( float ( max_size ) / float ( im_size_max ) ) im = cv2 . resize ( im , None , None , fx = im_scale , fy = im_scale , interpolation = cv2 . INTER_LINEAR ) return ( im , im_scale )
mean subtract and scale an image for use in a blob .