一:imread
用来读取图片,返回一个numpy.ndarray类型的多维数组,具有两个参数:
参数1 filename, 读取的图片文件名,可以使用相对路径或者绝对路径,但必须带完整的文件扩展名(图片格式后缀)
参数2 flags, 一个读取标记,用于选择读取图片的方式,默认值为IMREAD_COLOR,flag值的设定与用什么颜色格式读取图片有关
import cv2 path = 'E:Flow classificationemail_train1.jpg' image = cv2.imread(path) print(image) print(type(image))
二:newaxis
用来增加数组维度,如下:
import numpy as np a=np.array([1,2,3,4,5,6,7,8,9]) print(a.shape) print(a) b = a[:,np.newaxis] print(b.shape) print(b) c = b[:,:,np.newaxis] print(c.shape) print(c) d = c[:,:,:,np.newaxis] print(d.shape) print(d)
输出结果如下:
(9,) [1 2 3 4 5 6 7 8 9]
(9, 1) [[1] [2] [3] [4] [5] [6] [7] [8] [9]]
(9, 1, 1) [[[1]] [[2]] [[3]] [[4]] [[5]] [[6]] [[7]] [[8]] [[9]]] (9, 1, 1, 1) [[[[1]]] [[[2]]] [[[3]]] [[[4]]] [[[5]]] [[[6]]] [[[7]]] [[[8]]] [[[9]]]]
***************不积跬步无以至千里***************