210_Python+OpenCV_03_创建单通道和三通道的image

1~NumPy(https://www.numpy.org/)

NumPy is the fundamental package for scientific computing with Python(科学计算). It contains among other things:

  1. a powerful N-dimensional array object(功能强大的n维数组对象)

  2. sophisticated (broadcasting) functions

  3. tools for integrating C/C++ and Fortran code

  4. useful linear algebra, Fourier transform, and random number
    capabilities(现象代数、傅里叶变换、随机数)

Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases

2~ BGR blue green red 0-255——色彩空间

255表示白色
0 表示黑色

3~Python numpy函数:zeros()、ones()、empty()

  1. 在给数组赋初始值的时候,经常会用到0数组,而Python中,我们使用zeros()函数来实现。
  2. ones( )函数可以创建任意维度和元素个数的数组,其元素值均为1
  3. empty( )一样,只是它所常见的数组内所有元素均为空,没有实际意义,所以它也是创建数组最快的方法。
import  numpy as np
a = np.zeros(5)
a
Out[6]: array([0., 0., 0., 0., 0.])

在默认的情况下,zeros创建的数组元素类型是浮点型的,如果要使用其他类型,可以设置dtype参数进行声明

``
a = np.zeros(5,int)
a
Out[8]: array([0, 0, 0, 0, 0])

a = np.ones([2, 3])
a
Out[11]:
array([[1., 1., 1.],
[1., 1., 1.]])
a = np.zeros([4, 4, 3], np.uint8)
a
Out[15]:
array([[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]], dtype=uint8)
``
liyongling

你可能感兴趣的:(Z-归档_OpenCV)