BGR图像转RGB

OpenCV默认把图像读成BGR格式,因此需要转化。
def readImage(path):
    # OpenCV reads the image in bgr format by default
    bgr_img = cv2.imread(path)
    # We flip it to rgb for visualization purposes
    b,g,r = cv2.split(bgr_img)
    rgb_img = cv2.merge([r,g,b])
    return rgb_img
或者:img = Image.open(img_path).convert("RGB")

你可能感兴趣的:(BGR图像转RGB)