[Python] How can I detect T/X junctions but ignore 90° angled lines (L-turns) in OpenCV?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to distinguish between 90° angled lines (L-turns) and true junctions (T and X intersections) in OpenCV.

    I'm using morphological opening to extract long horizontal and vertical line segments, then ANDing them to get junction candidates:

    self.horizontal_kernel_junction = cv2.getStructuringElement(cv2.MORPH_RECT, (171, 1))
    self.vertical_kernel_junction = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 171))
    horizontal = cv2.morphologyEx(self.threshold, cv2.MORPH_OPEN, self.horizontal_kernel_junction, iterations=1)
    vertical = cv2.morphologyEx(self.threshold, cv2.MORPH_OPEN, self.vertical_kernel_junction, iterations=1)
    joints = cv2.bitwise_and(horizontal, vertical)
    cnts, _ = cv2.findContours(joints, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)


    This detects real junctions (example): junction

    But it also detects L-shaped 90° turns (example): L-shaped

    How can I detect only crossings (T and X junctions) and avoid detecting simple 90° L-turns?

    I've considered/tried:


    • Varying kernel sizes for the morphological operations (didn't solve it reliably).


    • Filtering by contour area (still picks up L-turns).

    Continue reading...

Compartilhe esta Página