This forum is disabled, please visit https://forum.opencv.org

1 | initial version |

Faster method use connected componnet and find contours 1-Find all connected components by using find FindContour method 2-Store contour for every Region(Connected componnet CC) 3-calculate the Bounding Rect for every region (CC) 4-Loop in all region 5-For every region , find the nearest regions depending on the Bounding rect 6-now you have the suspected regions which can be connected to region, compare the two contours and find the mimimum distance between the two contours , if the minimum distance is smaller than threshould (say 10 pixel) then now you can draw line from Point1 in first contour and point2 in second contour , Point1 and Point2 are the points which satisfy the minmum distance calculated before. 7-repeat the proces for all regions

2 | No.2 Revision |

Faster method use connected componnet and find ~~contours
1-Find ~~contours

- Find all connected components by using find FindContour
~~method 2-Store~~method - Store contour for every Region(Connected componnet
~~CC) 3-calculate~~CC) - calculate the Bounding Rect for every region
~~(CC) 4-Loop~~(CC) - Loop in all
~~region 5-For~~region - For every region , find the nearest regions depending on the Bounding
~~rect 6-now~~rect - now you have the suspected regions which can be connected to region, compare the two contours and find the mimimum distance between the two contours , if the minimum distance is smaller than threshould (say 10 pixel) then
~~before. 7-repeat~~before. - repeat the proces for all regions

3 | No.3 Revision |

Faster method use connected componnet and find contours

- Find all connected components by using find FindContour method
- Store contour for every Region(Connected componnet CC)
- calculate the Bounding Rect for every region (CC)
- Loop in all region
- For every region , find the nearest regions depending on the Bounding rect
- now you have the suspected regions which can be connected to region, compare the two contours and find the mimimum distance between the two contours , if the minimum distance is smaller than threshould (say 10 pixel) then now you can draw line from Point1 in first contour and point2 in second contour , Point1 and Point2 are the points which satisfy the minmum distance calculated before.
- repeat the proces for all regions

**EDIT:** you can find sample implemention code here

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.