Opencv绘制图像轮廓
cv2.drawContours(image, contours, contourIdx, color, thickness, lineType)
参数介绍
- image:待绘制轮廓的图像。注意:该函数会直接在图像上进行绘制轮廓,也就是说,在函数执行完毕之后,image不再是原始图像。因此,如果图像还有其他用途的话,记得备份。
- contours: 轮廓点。格式[ndarray0, ndarry1, …, ndarrayn]。
- contourIdx: 轮廓点索引值。值为0时,绘制contours中的ndarray0。值为1时,绘制contours中的ndarray1。值为负数(通常为-1)时,绘制所有的轮廓。
- color:轮廓颜色,格式为BGR。
- thickness: 可选参数。表示绘制轮廓时线条的粗细。值为负数(通常为-1)时,填充轮廓点内的区域。
- lineType: 可选参数。绘制轮廓的线型。
应用示例
import cv2
import numpy as np
# 创建图像
mask = np.zeros((600, 800, 3)