转换方式其实有两百多种 重点介绍这三种~~:彩色转灰度,BGR转RGB,灰度转BGR~~
1,彩色转灰度
b=cv2.cvtColor(a,cv2.COLOR_BGR2GRAY)
import cv2
import numpy as np
a=cv2.imread('F:\\Pycharm Project\\image\\lenacolor.jpg',cv2.IMREAD_UNCHANGED)
b=cv2.cvtColor(a,cv2.COLOR_BGR2GRAY)
cv2.imshow('a',a)
cv2.imshow('b',b)
cv2.waitKey()
cv2.destroyAllWindows()
2.BGR转RGB
b=cv2.cvtColor(a,cv2.COLOR_BGR2RGB)
import cv2
import numpy as np
a=cv2.imread('F:\\Pycharm Project\\image\\lenacolor.jpg',cv2.IMREAD_UNCHANGED)
b=cv2.cvtColor(a,cv2.COLOR_BGR2RGB)
cv2.imshow('original',a)
cv2.imshow('RGB',b)
cv2.waitKey()
cv2.destroyAllWindows()