cv2.cvtColor()处理图像类型的转换
import os
import cv2
import numpy as np
import matplotlib.pyplot as plt
def read_img(img_7_path,img_8_path):
img=cv2.imread(img_7_path)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
rgb=cv2.cvtColor(gray,cv2.COLOR_GRAY2BGR)
print("img.shape=",img.shape)
print("gray.shape=", gray.shape)
print("rgb.shape=", rgb.shape)
cv2.imshow('img',img)
cv2.imshow('gray',gray)
cv2.imshow('rgb',rgb)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
work_path = os.getcwd()
data_path = os.path.join(work_path, 'data')
img_7_path = os.path.join(data_path, '7.jpg')
img_8_path = os.path.join(data_path, '8.jpg')
read_img(img_7_path,img_8_path)