import numpy as np
import cv2
im = cv2.imread('image/canny.png')
# 寻找轮廓前要对其进行灰度化、二值化处理(也可使用canny进行边缘检测)
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
cv2.imshow("th", thresh)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
'''# 绘制所有轮廓
img = cv2.drawContours(im, contours, -1, (0,255,0), 3)
# 绘制第四个轮廓
img = cv2.drawContours(im, contours, 3, (0,255,0), 3)'''
# 绘制第14个轮廓
cnt = contours[13]
img = cv2.drawContours(im, [cnt], 0, (0,255,0), 3)
cv2.imshow('res',img)
cv2.waitKey(0)