如何绘制轮廓?蟒蛇

问题描述 投票:-1回答:1

我试图在源图像中绘制十个最大轮廓,但它们不会出现。

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)

Source image

python opencv find draw contour
1个回答
0
投票

代码工作得很好。因为它的形象很大,你无法看到。在imshow之前添加此行,您将看到轮廓。

image_contours = cv2.resize(image_contours, None, fx=0.25,fy=0.25 , interpolation = cv2.INTER_CUBIC)
© www.soinside.com 2019 - 2024. All rights reserved.