def bgr2gray(img, keepdim=False):
out_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)<EOL>if keepdim:<EOL><INDENT>out_img = out_img[..., None]<EOL><DEDENT>return out_img<EOL>
Convert a BGR image to grayscale image.

    Args:
        img (ndarray): The input image.
        keepdim (bool): If False (by default), then return the grayscale image
            with 2 dims, otherwise 3 dims.

    Returns:
        ndarray: The converted grayscale image.