1 | initial version |
Probably you can tune the parameters of the probabilistic Hough transform to detect all the lines; however it will sometimes bridge the gaps.
You can try to compute the skeleton transform of the image (cv.ximgproc.thinning) then follow every line. The endpoints are the pixels having only one neighbor. To bridge the gaps, you can search in the neighborhood of an endpoint for another endpoint (also check if the directions match).