opencv得到图像轮廓后如何将轮廓放在坐标轴并得到每个点的坐标
时间: 2023-04-03 14:03:27 浏览: 91
您好,对于您的问题,可以使用cv2.findContours()函数获取图像轮廓,然后使用cv2.drawContours()函数将轮廓绘制在坐标轴上。可以使用numpy库中的ndarray来存储每个点的坐标。具体实现可以参考以下代码:
```
import cv2
import numpy as np
# 读取图像
img = cv2.imread('image.jpg')
# 转换为灰度图像
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 二值化处理
ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
# 获取轮廓
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# 绘制轮廓
cv2.drawContours(img, contours, -1, (0, 255, 0), 2)
# 获取每个点的坐标
points = []
for contour in contours:
for point in contour:
x, y = point[0]
points.append([x, y])
# 将坐标存储为ndarray
points = np.array(points)
# 显示结果
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
希望能够帮到您!