【发布时间】:2018-07-09 18:02:15
【问题描述】:
我正在尝试在源图像中绘制十个最大的轮廓,但它们没有出现。
import cv2
image_orig=cv2.imread('C:\Users\pc\Desktop\middleeast.jpg')
image_gray=cv2.cvtColor(image_orig,cv2.COLOR_BGR2GRAY)
image_contours=image_orig.copy()
_, image_threshold=cv2.threshold(image_gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
_,contours,_=cv2.findContours(image_threshold,cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
largest_contours = sorted(contours, key=cv2.contourArea)[-10:]
print len(largest_contours)
for contour in largest_contours:
print cv2.contourArea(contour)
cv2.drawContours(image_contours, largest_contours, -1, (255,255,0), 3)
cv2.imshow('contours',image_contours)
cv2.waitKey(0)
【问题讨论】:
-
你有什么错误吗?
-
@Aaron 没有错误,使用 cv2.drawContours 后轮廓不会出现
标签: python opencv find draw contour