【发布时间】:2018-07-05 04:29:59
【问题描述】:
我有图片
我正在寻找 python 解决方案,根据图像中的轮廓将该图像中的形状分解成更小的部分。
我已经研究过 Canny 和 OpenCV 中的 findContours 的解决方案,但它们都不适合我。
编辑:
使用的代码:
使用 Canny 方法
import cv2 import numpy as np
img = cv2.imread('area_of_blob_maxcontrast_white.jpg') edges = cv2.Canny(img, 100, 200)
cv2.imwrite('area_of_blob_maxcontrast_white_edges.jpg',edges)
使用 findContours 方法
import numpy as np
import argparse
import cv2
image = cv2.imread('area_of_blob_maxcontrast_white.png')
lower = np.array([0, 0, 0]) upper = np.array([15, 15, 15]) shapeMask = cv2.inRange(image, lower, upper)
(_,cnts, _) = cv2.findContours(shapeMask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE) print "I found %d black shapes" % (len(cnts)) cv2.imshow("Mask", shapeMask)
for c in cnts:
# draw the contour and show it
cv2.drawContours(image, [c], -1, (0, 255, 0), 2)
cv2.imshow("Image", image)
cv2.waitKey(0)
【问题讨论】:
-
请分享您尝试的示例代码,以便人们找到并指出您的代码需要更改的地方。
-
图片在哪里?
-
这是图片的链接:i.stack.imgur.com/dVBTT.jpg
标签: python opencv image-segmentation