cv2.imread() | (文件路径,flags) | 读取图像 | cv2.imshow() | (图像title,图片对象) | 显示图像 | cv2.imwrite() | (文件名,图片对象) | 保存图像 | cv2.split() | | | cv2.merge() | | | cv2.waitKey() | | | cv2.destroyAllWindows() | | |
图片的读取
图像属性读取
img = cv2.imread(r'C:\Users\Administrator\Desktop\beginning.jpg')
dimensions = img.shape
print(dimensions)
total_number_of_elements= img.size
print(total_number_of_elements)
image_dtype = img.dtype
print(image_dtype)
原图像读取
import cv2
img_OpenCV = cv2.imread(r'C:\Users\Administrator\Desktop\beginning.jpg')
cv2.imshow('bgr image', img_OpenCV)
cv2.waitKey(0)
cv2.destroyAllWindows()
灰度方式读取
img_OpenCV = cv2.imread(r'C:\Users\Administrator\Desktop\beginning.jpg',cv2.IMREAD_GRAYSCALE)
或
img_OpenCV = cv2.imread(r'C:\Users\Administrator\Desktop\beginning.jpg',2)
cv2.imread参数说明:cv2.imread(文件路径,flags)
文件路径——一般使用绝对路径即可 flags=1——读取前后,图片格式不变 flags=2——读取后,图片格式转为灰度图 flags=3——读取后,图片格式转为BGR三信道图像
RGB通道更改顺序
b, g, r = cv2.split(img_OpenCV)
img_matplotlib = cv2.merge([r, g, b])
只显示某一通道
img_OpenCV = cv2.imread(r'C:\Users\Administrator\Desktop\beginning.jpg')
img_OpenCV[:, :, 1]=0
img_OpenCV[:, :, 2]=0
读取某个像素点的通道值
img = cv2.imread(r'C:\Users\Administrator\Desktop\beginning.jpg')
(b, g, r) = img[0, 0]
print(b)
print(g)
print(r)
x=img[0, 0,0]
y=img[0, 0,1]
z=img[0, 0,2]
print(x)
print(y)
print(z)
读取图像的局部
图像的预处理
图像灰度化 图像去噪声
轮廓识别
颜色识别
形状识别
数字识别
图像的保存
cv2.imwrite('data/1.png',img)
|