Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- # 读取图像
- image = cv2.imread('road1.jpg')
- # 转换为灰度图
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- # 轮廓检测
- blurred = cv2.GaussianBlur(gray, (5, 5), 0)
- edges = cv2.Canny(blurred, 5, 50)
- contours, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
- # 绘制轮廓并填充红色
- for contour in contours:
- if cv2.contourArea(contour) > 2000: # 过滤
- cv2.drawContours(image, [contour], -1, (0, 0, 255), -1)
- # 显示和保存结果图像
- cv2.imshow('1', edges)
- cv2.imshow('Detected Potholes', image)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
- cv2.imwrite('result_4.jpg', image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement