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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值