Recognizing Rectangle shape
I have a list of points of a stroke and I want to detect if this stroke is rectangular. So 4 angles of approximately 90 degrees. Afterwards I need the size, position and orientation of 开发者_Python百科the rectangle.
I am using C# but algorithms in other languages or pseudocode are also usefull.
Thanks
Well, I've made something like this a while ago.
You can download it here.
http://up352.siz.co.il/up2/lhmjmdenn53m.png
This thing allows you to detect edges - as you see its pretty accurate.
When you get the edges all you need is to calculate the angles between them - and if it's ~ 90 then its a rectangle.
I'll assume that you collected each stroke into a separate list:
- Find the trend line for the stroke (I'd start with Simple linear regression for this).
- Find the angle between the each two intersecting trend lines (compare to 90 deg with some threshold).
- Find orientation (angle) of any of the trend lines to get orientation of shape (of course anything which is near 0 mod 90 deg is the same as 0 in case of a square).
Find the length of any of the trend lines (distance from one intersection to the other), and the length of on of it's adjacent (intersecting) lines, these two lengths will be your length and width (or width and height if you like) for size calculation (area, or anything else).
- In step 1 you can use many trend line computing algorithms, and it might be worth your time checking a few of them out.
In case all points are sampled into the same collection, you first need to break this collection into the 4 strokes (which is a though task on it's own...tougher task)
精彩评论