我想检测所有角点和起点,终点。我可以检测起点和终点,但曲线无法检测。这是我的代码
from scipy.ndimage import generic_filter
def lineEnds(P):
return 255 * ((P[4]==255) and np.sum(P)==510)
image = cv2.imread("./dataset/test.jpg" , cv2.COLOR_RGB2GRAY)
result = generic_filter(image , lineEnds, (3, 3))
答案 0 :(得分:3)
您也可以使用OpenCV
检测角点
import cv2
image = cv2.imread('./test.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect corners in the image
corners = cv2.goodFeaturesToTrack(gray, 500, qualityLevel=0.01, minDistance=20)
for c in corners:
x, y = c.reshape(2)
print(x, y)
# draw a circle around the detected corner
cv2.circle(image, (x, y), radius=4, color=(0, 255, 120), thickness=2)
cv2.imshow("Result", image)
cv2.waitKey(0)
结果:
有关更多详细信息,请查看以下文档: