【发布时间】:2016-06-16 08:36:17
【问题描述】:
我想检测下图中的两个斑点:
原文:
我想像这样检测内部:
我也想检测到外圈:
但我现在正在应用 OpenCV 的简单 blob 检测,但它并没有给我想要的结果。这是我的代码:
# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector()
# Detect blobs.
keypoints = detector.detect(image)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(image, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
final = Image.fromarray(im_with_keypoints)
final.show()
但这是斑点检测器检测到的:
OpenCV 中的 Hugh Circle 检测也不能正确识别这两种形状。
更新: 我也尝试过椭圆拟合,但它没有检测到任何一个斑点,而是检测到图像中的一些随机线。这是我用于椭圆拟合的代码。
ret,thresh = cv2.threshold(image,127,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
M = cv2.moments(cnt)
print M
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
ellipse = cv2.fitEllipse(cnt)
cv2.ellipse(im2,ellipse,(0,255,0),2)
final = Image.fromarray(image)
final.show()
感谢您在检测这些 blob 方面的任何帮助。
【问题讨论】:
-
嗨,你觉得我下面的回答有用吗?任何 cmets 表示赞赏。谢谢。
标签: python opencv matplotlib computer-vision edge-detection