小编Vik*_*mar的帖子

在python中使用cv2.approxPolyDP()绘制轮廓

我无法使用cv2.approxPolyDP().

我得到以下结果:

我的结果

但我想要这样的输出:

这就是我要找的

这是我的代码:

import cv2
im = cv2.imread('C:\Python27\Test\Targets\s1.jpg') # read picture

imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) # BGR to grayscale

ret, thresh = cv2.threshold(imgray, 200, 255, cv2.THRESH_BINARY)

countours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

epsilon = 0.1 * cv2.arcLength(countours[0], True)
approx = cv2.approxPolyDP(countours[0], epsilon, True)

cv2.drawContours(im, approx, -1, (0, 255, 0), 3)
cv2.imshow("Contour", im)

cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

python opencv image computer-vision opencv3.0

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

computer-vision ×1

image ×1

opencv ×1

opencv3.0 ×1

python ×1