脚本专栏 
首页 > 脚本专栏 > 浏览文章

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

(编辑:jimmy 日期: 2024/10/20 浏览:3 次 )

原始图

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)
上一篇:Pycharm安装python库的方法
下一篇:scrapy处理python爬虫调度详解
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。