Author: Not specified Language: python
Description: Not specified Timestamp: 2013-06-06 16:09:13 +0000
View raw paste Reply
  1. def is_parallelogram(cnt, maxerr=0.1):
  2.     cnt = cnt.reshape(-1, 2)
  3.     dist = lambda p1, p2: sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
  4.     lengths = [dist(cnt[i], cnt[(i+1) % 4]) for i in range(4)]
  5.     diff_w = abs(lengths[0] - lengths[2])
  6.     diff_h = abs(lengths[1] - lengths[3])
  7.  
  8.     return (diff_w / lengths[0] < maxerr) and (diff_w / lengths[2] < maxerr) and \
  9.            (diff_h / lengths[1] < maxerr) and (diff_h / lengths[3] < maxerr)
  10.  
View raw paste Reply