Article 593R3 [SOLVED] Detecting polygon coordinates of shapes in images

[SOLVED] Detecting polygon coordinates of shapes in images

by
boughtonp
from LinuxQuestions.org on (#593R3)
I'm trying to detect coordinates of polygons from black & white images.

There's a lot of people doing similar-but-not-quite-the-same things, and every example I've found uses OpenCV findContours. This will find the shapes, but appears to do so by identifying points at every single pixel along the outline of the polygon, instead of only at corners/angles.

The findContours method does allow specifying a Contour Approximation Mode to reduce the points, but CHAIN_APPROX_SIMPLE doesn't handle lines that are not at 45 or 90 degrees, and the only other options of CHAIN_APPROX_TC89_L1 or CHAIN_APPROX_TC89_KCOS still return 20 points for a rotated square (and 23 for an irregular hexagon).

Attached is a simplified test image, plus the actual vs desired outputs.

I can't find any reference to other people having the same problem, so it seems likely I'm going to have to write my own code to filter out unwanted points, but - before I spend too much time on that - does anyone happen to know:

* Is there an option to use a different chain approximation algorithm in OpenCV that can actually identify straight lines.

* Are there any alternatives to findContours (either another part of OpenCV or another library) that might do a better job?

Thanks.

Attached Thumbnailsattachment.php?attachmentid=34303&stc=1& attachment.php?attachmentid=34304&stc=1& attachment.php?attachmentid=34305&stc=1& latest?d=yIl2AUoC8zA latest?i=jtwWLDRgC-k:Z20y4HNuwJ4:F7zBnMy latest?i=jtwWLDRgC-k:Z20y4HNuwJ4:V_sGLiP latest?d=qj6IDK7rITs latest?i=jtwWLDRgC-k:Z20y4HNuwJ4:gIN9vFwjtwWLDRgC-k
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments