break up contours found by findContours

asked 2017-03-18 19:19:22 -0600

everphilski gravatar image

updated 2017-03-18 20:05:55 -0600

Good Evening,

I'm trying to use OpenCV to detect remote controlled robots in an arena. These robots typically contrast well with the surroundings so my approach has been to use the Canny detector to find edges and then use findContours to filter out contours I don't care about. (Please refer to linked image) For example in the top left image I don't care about the long straight lines that are caused by the edge of the arena. In general I can discard these by aspect ratio. However in some cases (bottom left) findContours keeps multiple lines in one contour and then fills in a box (grey in bottom right)

My question is, is there a way to break up these lines output from findContours ?

I have played with thresholds on the Canny detctor and while higher quality does tend to break up those lines it also loses track on those robots (which apparently are not high quality features! :) )

image description

I tried feeding my Canny image into HoughLinesP to remove lines. After some tweaking the situation is improved (see figure) now I just have small triangles instead of large quadrilateral.

image description

I am still looking for a solution to break up lines remaining in the canny image.



edit retag flag offensive close merge delete


As a quick idea you could try to use approxPolyDP and split original contour at polygon points. Depending on epsilon value you get segments of straight lines.

matman gravatar imagematman ( 2017-03-19 06:10:16 -0600 )edit

Is the robtos moving?Do you use camera or just the picture?

jsxyhelu gravatar imagejsxyhelu ( 2017-03-20 05:16:51 -0600 )edit