Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contour approximation containing undesired points

Hi there i have a polygon problem. I don't know what to look for so i decided to ask here. The image below shows a simple shape. The contours are detected with OpenCV's findContours() and aproximated by the CV_CHAIN_APPROX_TC89_KCOS (for those who want to know how this is done) algorithm, so that all points in a line, are summarized to a single line. So anyways some contours contain some sort of, i call it noise, in the shape. The image below shows what is meant with noise. The red line is the contour. (Sorry no ms paint skills)

enter image description here

My goal is to redefine the shape to approximate the shape, but leave out this "noise". So the contour should look like this. The blue line shows the corrected contour.

enter image description here

like image 669
Arndt Bieberstein Avatar asked Jan 17 '13 10:01

Arndt Bieberstein


2 Answers

  1. Try to detect corners with...cvGoodFeatuersToTrack()....but have a criteria that corners should be separated by a good amount of distance...if corners form a cluster discard them.
  2. From the list of points that are in the contour...choose the point with (highest x, highest y), (highest x, lowest y), (lowest x, highest y) and (lowest x, lowest y)....now join these four points...
  3. If you have 'noise' at the corners itself then try to detect straight lines in the image using Hough's transform...
like image 99
rotating_image Avatar answered Oct 06 '22 08:10

rotating_image


I can propose one more approach:

1)You can use Hough Line Transform to detect lines on your image (before use Canny to detect contours). You can not take into consideration small lines by using rather big threshold (the minimum number of intersections to “detect” a line) in method HoughLinesP.

2) After finding all lines you can find their intersection as it is described here by @DanielHsH. So you will be able to find all corners.

like image 33
Ann Orlova Avatar answered Oct 06 '22 08:10

Ann Orlova