1 | initial version |
You could use cv::findContours to get all the exterior contours of your objects. A contour is in fact a vector of cv::Point, so you could write a function that analyzes contour pairs, looking for the closest 2 points on those contours. You could then use cv::line to dray a small line segment in the image, between those 2 points, on condition that they're not too far from each other. In the end, you re-extract the contours. You can play with the functions in Structural Analysis and Shape Descriptors, like cv::boxPoints to extract interesting properties.
You can dilate the image (cv::dilate) with a radial kernel large enough to bridge the gaps. Then you extract the contours and/or connected components, and when estimating the length, you can subtract the kernel size from whatever measure you obtain.
2 | No.2 Revision |
You could use cv::findContours to get all the exterior contours of your objects. A contour is in fact a vector of cv::Point, so you could write a function that analyzes contour pairs, looking for the closest 2 points on those contours. You could then use cv::line to dray draw a small line segment in the image, between those 2 points, on condition that they're not too far from each other. In the end, you re-extract the contours. You can play with the functions in Structural Analysis and Shape Descriptors, like cv::boxPoints to extract interesting properties.
You can dilate the image (cv::dilate) with a radial kernel large enough to bridge the gaps. Then you extract the contours and/or connected components, and when estimating the length, you can subtract the kernel size from whatever measure you obtain.