[Python] Different versions of opencv-python detecting different number of lines for the same...

Discussão em 'Python' iniciado por Stack, Junho 25, 2025.

  1. Stack

    Stack Membro Participativo

    Two versions of opencv-python, ver. 3.4.5.20 (Python 2.7.18) and ver. 4.11.0.86 (Python 3.12.0) were used for line segment detection

    Both version of opencv-python implements the following paper (algorithm):


    Rafael Grompone von Gioi, Jérémie Jakubowicz, Jean-Michel Morel, and Gregory Randall. Lsd: a line segment detector. 2012.
    ​

    Proof:- LSD for ver. 3.4.5 LSD for ver. 4.11.0

    One of the examples in which the number of lines detected for the same grayscale image, is different, is for the following gray_scale image:- Grayscale values for 512x512 image

    For this image the opencv-python ver. 3.4.5.20 detects 176 lines and ver. 4.11.0.86 detects 177 lines.

    Code that was used for both version.

    import cv2
    import numpy

    lsd = cv2.createLineSegmentDetector(0)
    lines = lsd.detect(np.array(gray))


    To recreate, the value of file can be simply assigned to the gray as:-

    gray = lsd.detect( copy paste the content of the file here)

    To check the number of lines: print(len(lines[0]))

    Is there a way or a workaround so that the output of lsd.detect of ver. 3.4.5 is replicated to ver. 4.11.0.86 ?

    Continue reading...

Compartilhe esta Página