在python项目中使用 opencv怎么实现一个角点检测连线功能

在python项目中使用 opencv怎么实现一个角点检测连线功能?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

角点检测

points = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)
points = np.int0(points).reshape(-1,2)

for point in points:
  x, y = point.ravel()
  cv2.circle(img, (x, y), 10, (0, 255, 0), -1)

连线

cv2.line(img, (0, y1), (1000, y1), (0, 255, 0), thickness=3, lineType=8)
cv2.line(img, (0, y2), (1000, y2), (0, 255, 0), thickness=3, lineType=8)

完整代码

""" 
@author: qq群686070107
""" 
import cv2
import numpy as np
img=cv2.imread("1.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
points = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)
points = np.int0(points).reshape(-1,2)

for point in points:
  x, y = point.ravel()
  cv2.circle(img, (x, y), 10, (0, 255, 0), -1)


y1 = min(points[:,1])
y2 = max(points[:,1])

## small and big enough 
cv2.line(img, (0, y1), (1000, y1), (0, 255, 0), thickness=3, lineType=8)
cv2.line(img, (0, y2), (1000, y2), (0, 255, 0), thickness=3, lineType=8)

cv2.imshow("img", img)
cv2.waitKey(0)

看完上述内容,你们掌握在python项目中使用 opencv怎么实现一个角点检测连线功能的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!