0

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

Or use the grayscale image: (dropbox link)

enter image description here

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 ?

Purpose of replication of result: An application backend was originally written in Python 2.7 and now needs to be rewritten in Python 3.12. I need to replicate the results, but because the number of line segments is different, I am unable to do so.

14
  • 2
    no need for this complication. save the image as a PNG, then add it to the post. this site should keep it a PNG. this is strongly recommended because we can't predict when that off-site link will top working (when that file will no longer be in that dropbox). Commented Jun 25 at 6:14
  • what made you use opencv version 3 instead of 4? is there anything that forces you to use that version? Commented Jun 25 at 6:16
  • An application which requires detection of floor uses opencv python 3.4.5.20 (on Python 2.7.18). Now I need to replicate the result to the new Python, version 3.12.0 (opencv-python ver. 4.11.0.86) and during the process I encountered this difference for which the effect to the output is major. Note:- I've added gray_scale PNG. Commented Jun 25 at 7:04
  • 1
    Implementations change, bugs get fixed. You cannot expect to replicate results exactly. Does the exact number of lines detected affect the final output of the program? Is the program output affected qualitatively? Commented Jun 25 at 11:42
  • 2
    Also, the code could be identical, but give a slightly different results because it’s compiled with a different version of the compiler. One more line is a typical result of a value being really close to the threshold, and whether it is above or below depends on a rounding error. Commented Jun 25 at 11:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.