我想检测线上的所有角点和起点、终点。我可以检测到起点和终点,但无法检测到曲线。这是我的代码
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))
最佳答案
您也可以使用 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)
结果:
有关更多详细信息,请查看这些文档:
关于python - 如何获得直线上的曲线点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64496777/