转换成RGB
import cv2 import numpy as ny img = ny.zeros( ( 3 , 3 ),ny.float32) img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB) print(img)
将jpg装成png
import cv2 image=cv2.imread('C:/Users/Albert/PycharmProjects/CVTest/image/1.jpg') cv2.imwrite('C:/Users/Albert/PycharmProjects/CVTest/image/1.png',image)
读入灰度图像
import cv2 image=cv2.imread('C:/Users/Albert/PycharmProjects/CVTest/image/1.jpg',cv2.IMREAD_GRAYSCALE) cv2.imwrite('C:/Users/Albert/PycharmProjects/CVTest/image/11.png',image)
图像的相对路径是指python脚本所在的文件夹
B、G、R
将图像的绿色通道设置为0
import cv2 image=cv2.imread('C:/Users/Albert/PycharmProjects/CVTest/image/1.jpg') image[:,:,1]=0 cv2.imshow('a',image) cv2.waitKey(0)
图像基本属性
import cv2 image=cv2.imread('C:/Users/Albert/PycharmProjects/CVTest/image/1.jpg') print(image.shape) print(image.size) print(image.dtype)