python opencv 基本操作

  • 1、imread—读取图像
  • 2、imshow—显示图像
  • 3、imwrite—保存图像
  • 4、zeros—构造全0矩阵
  • 5、line—画线
  • 6、rectangle—画矩形
  • 7、circle—画圆形
  • 8、randint—产生[low,high)中的随机整数

1、imread—读取图像

函数原型:imread(filename, flags=None)

filename:读取的图像路径名;例如:”H:\img\lena.jpg”。

flags:彩色图or灰色图,1:表示彩色图;0:表示灰色图。

2、imshow—显示图像

函数原型:imshow(winname, mat)

winname:窗口名字;例如:”Lena”。

mat:要显示的图像矩阵。

3、imwrite—保存图像

函数原型:imwrite(filename, img, params=None)

filename:保存到的图像路径名;例如:”H:\img\Newlena.jpg”。

img:要保存的图像矩阵;例如:image。

params:缺省的参数。

4、zeros—构造全0矩阵

函数原型:zeros(shape, dtype=None, order=’C’)

shape:矩阵大小;例如:300x300;

dtype:数据类型;例如:”uint8”

order:数据排列顺序,默认按列排的

5、line—画线

函数原型:line(img, pt1, pt2, color, thickness=None, lineType=None, shift=None)

img:在img上绘图;

pt1:起点;例如:(0,0)

pt2:终点;例如:(300,300)

color:线的颜色;例如:(0,255,0)(绿色)

thickness:线的粗细程度,例如:-1,1,2,3…

其它参数默认即可。

6、rectangle—画矩形

函数原型:rectangle(img, pt1, pt2, color, thickness=None, lineType=None, shift=None)

img:在img上绘图;

pt1:起点;例如:(0,0)

pt2:终点;例如:(300,300)

color:线的颜色;例如:(0,255,0)(绿色)

thickness:线的粗细程度,例如:-1,1,2,3…

其它参数默认即可。

7、circle—画圆形

函数原型:circle(img, center, radius, color, thickness=None, lineType=None, shift=None)

img:在img上绘图;

center:圆心;例如:(0,0)

radius:半径;例如:20

color:线的颜色;例如:(0,255,0)(绿色)

thickness:线的粗细程度,例如:-1,1,2,3…

其它参数默认即可。

8、randint—产生[low,high)中的随机整数

函数原型:randint(low, high=None, size=None)

low:区间下界;例如:0

high:区间上界;例如:256

size:个数;例如:size = (2,),产生2个随机整数

你可能感兴趣的:(opencv,python,Python)