Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
830 B
2
Indexable
Never
def contains_pothole(image_path):
    # Read the image
    image = cv2.imread(image_path, 0)  # 0 to read image in grayscale mode

    # Preprocessing the image
    blurred = cv2.GaussianBlur(image, (5, 5), 0)
    edged = cv2.Canny(blurred, 50, 150)

    # Find contours in the edged image
    contours, _ = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    # Heuristic to determine if an image contains a pothole
    for contour in contours:
        # Approximate the contour shape
        peri = cv2.arcLength(contour, True)
        approx = cv2.approxPolyDP(contour, 0.02 * peri, True)

        # Consider a contour as a pothole if it has a complex shape and sizable area
        if len(approx) > 8 and cv2.contourArea(contour) > 100:
            return True

    return False
Leave a Comment