BGR与RGB转换

对使用到opencv存图的地方,均需要进行颜色读取形式,misc读取图片时是RGB格式,cv2中是BGR格式,需要将格式统一,否则

图片显示颜色存在错误

def colorMerge(image):
    """
    用于将RGB格式转换为BGR
    :param im    elif :age:   RGB格式读取的图像数据
    :return:      BGR格式的图像数据
    """
    if image.shape[2] == 3:
        r, g, b = cv2.split(image)
        img = cv2.merge([b, g, r])
        return img
    elif image.shape[2] == 4:
        r, g, b, a = cv2.split(image)
        img = cv2.merge([b, g, r])
        return img

猜你喜欢

转载自blog.csdn.net/Dawn__Z/article/details/86468976
今日推荐