目录
一:查找绘制轮廓
# 读取图像并转换为灰度图像
image = cv2.imread('D://test_python/open_cv/cp1.jpeg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 进行边缘检测
edges = cv2.Canny(gray, 50, 150)
# 查找轮廓
contours, hierarchy = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# 绘制轮廓
cv2.drawContours(image, contours, -1, (0, 255, 0), 2)
# 显示结果
cv2.imshow("Contours", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
使用OpenCV库来读取一张图像,将其转换为灰度图像,然后进行边缘检测,查找轮廓,并在原始图像上绘制这些轮廓