答案 0 :(得分:3)
如果您只想检测椭圆形 而不想使用HoughLines,则可以如下使用SimpleBlobDetector:
注意:我用python编写了此代码,因为它的实现速度更快。该代码非常容易转换为C ++ IMO
import numpy as np
import cv2
image = cv2.imread("remove_lines.jpg")
imgray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply morph closing to improve the connection between ovals (complete the ovals)
kernel = np.ones((5,5), np.uint8)
imgray = cv2.morphologyEx(imgray, cv2.MORPH_CLOSE, kernel=kernel)
# Set parameters for blob detection
params = cv2.SimpleBlobDetector_Params()
# This is to remove any "small" blobs
params.filterByArea = True
params.minArea = 200
# bit easy on the circularity here, circle = 1
params.filterByCircularity = True
params.minCircularity = 0.7
# Convexity = Area of Blob / Area of its convex hull
params.filterByConvexity = True
params.minConvexity = 0.1
# Measure how elongated the shape is, line = 0, circle = 1, very easy here as well
params.filterByInertia = True
params.minInertiaRatio = 0.01
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(imgray)
im_with_points = cv2.drawKeypoints(image, keypoints, np.array([]), (0, 0, 255),
cv2.DrawMatchesFlags_DRAW_RICH_KEYPOINTS)
cv2.imshow("Keypoints", im_with_points)
cv2.waitKey(0)
结果: