python opencv角点检测连线功能的实现代码

(编辑:jimmy 日期: 2024/9/21 浏览:2)

原始图

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)

python opencv角点检测连线功能的实现代码

连线

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)

python opencv角点检测连线功能的实现代码

完整代码

""" 
@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)
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。