python如何查看我的图片是RGB格式还是BGR格式?我如何转换它们,反之亦然?
How to check whether my image is RGB format or BGR format in python? How do i convert them and viceversa?
我正在对 OpenVino 模型中的预训练数据进行一些预处理。
它说它只使用BGR格式图像。
在这里,
如何检查python我的图像是 BGR 格式还是 RBG 格式?
我加载的图像代码是
import cv2
import numpy as np
from PIL import Image
image = cv2.imread('29101878_988024658021087_5045014614769664000_o.jpg')
print(image.shape)
给出输出
形状 (973,772,3)
如何检查图像是 RBG 还是 BGR 格式?
如果它是 RBG 格式,我如何将它转换为 BGR,反之亦然?
当您使用 opencv(imread、VideoCapture)时,图像以 BGR 颜色加载 space。
参考:
Note: In the case of color images, the decoded images will have the channels stored in B G R order.
Link : https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#imread)
要进行转换,您可以使用
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
反之亦然。
要检查图像是 RGB 还是 BGR 格式,我们可以使用:
import cv2
from PIL import Image
image = cv2.imread('image path')
img = Image.fromarray(image)
img.mode
我正在对 OpenVino 模型中的预训练数据进行一些预处理。 它说它只使用BGR格式图像。
在这里, 如何检查python我的图像是 BGR 格式还是 RBG 格式?
我加载的图像代码是
import cv2
import numpy as np
from PIL import Image
image = cv2.imread('29101878_988024658021087_5045014614769664000_o.jpg')
print(image.shape)
给出输出
形状 (973,772,3)
如何检查图像是 RBG 还是 BGR 格式? 如果它是 RBG 格式,我如何将它转换为 BGR,反之亦然?
当您使用 opencv(imread、VideoCapture)时,图像以 BGR 颜色加载 space。
参考:
Note: In the case of color images, the decoded images will have the channels stored in B G R order.
Link : https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#imread)
要进行转换,您可以使用
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
反之亦然。
要检查图像是 RGB 还是 BGR 格式,我们可以使用:
import cv2
from PIL import Image
image = cv2.imread('image path')
img = Image.fromarray(image)
img.mode