如何编写Python OpenCV实现角点检测与连线功能的具体代码?
- 内容介绍
- 文章标签
- 相关推荐
本文共计350个文字,预计阅读时间需要2分钟。
原始代码中,使用OpenCV的`cv2.goodFeaturesToTrack`函数检测图像中的特征点,并在图像上绘制这些点及其连线。以下是简化后的代码内容:
python使用cv2.goodFeaturesToTrack检测图像特征点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, y), (1000, y), (0, 255, 0), 1)
原始图
角点检测
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角点检测 连线功能的实现代码的文章就介绍到这了,更多相关python opencv角点检测内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!
本文共计350个文字,预计阅读时间需要2分钟。
原始代码中,使用OpenCV的`cv2.goodFeaturesToTrack`函数检测图像中的特征点,并在图像上绘制这些点及其连线。以下是简化后的代码内容:
python使用cv2.goodFeaturesToTrack检测图像特征点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, y), (1000, y), (0, 255, 0), 1)
原始图
角点检测
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角点检测 连线功能的实现代码的文章就介绍到这了,更多相关python opencv角点检测内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

