cv2.drawContours()
cv2.drawContours(image, contours, contourIdx, color, thickness=None, lineType=None, hierarchy=None, maxLevel=None, offset=None)
- 第一个参数是指明在哪幅图像上绘制轮廓;image为三通道才能显示轮廓
- 第二个参数是轮廓本身,在Python中是一个list;
- 第三个参数指定绘制轮廓list中的哪条轮廓,如果是-1,则绘制其中的所有轮廓。后面的参数很简单。其中thickness表明轮廓线的宽度,如果是-1(cv2.FILLED),则为填充模式。
import cv2 import numpy as np img=cv2.imread('test.jpg') imgray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ret,thresh=cv2.threshold(imgray,127,255,0) image,contours,hierarchy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) cv2.imshow('imageshow',image) # 显示返回值image,其实与输入参数的thresh原图没啥区别 cv2.waitKey(0) img=cv2.drawContours(img,contours,-1,(0,255,0),5) # img为三通道才能显示轮廓 cv2.imshow('drawimg',img) cv2.waitKey(0) cv2.destroyAllWindows()


发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/214674.html原文链接:https://javaforall.net
