affine_detect(detector, img, mask=None, pool=None) -> keypoints, descrs Apply a set of affine transormations to the image, detect keypoints and reproject them into initial image coordinates. See http://www.ipol.im/pub/algo/my_affine_sift/ for the details. ThreadPool object may
(detector, img, mask=None, pool=None)
| 67 | |
| 68 | |
| 69 | def affine_detect(detector, img, mask=None, pool=None): |
| 70 | ''' |
| 71 | affine_detect(detector, img, mask=None, pool=None) -> keypoints, descrs |
| 72 | |
| 73 | Apply a set of affine transormations to the image, detect keypoints and |
| 74 | reproject them into initial image coordinates. |
| 75 | See http://www.ipol.im/pub/algo/my_affine_sift/ for the details. |
| 76 | |
| 77 | ThreadPool object may be passed to speedup the computation. |
| 78 | ''' |
| 79 | params = [(1.0, 0.0)] |
| 80 | for t in 2**(0.5*np.arange(1,6)): |
| 81 | for phi in np.arange(0, 180, 72.0 / t): |
| 82 | params.append((t, phi)) |
| 83 | |
| 84 | def f(p): |
| 85 | t, phi = p |
| 86 | timg, tmask, Ai = affine_skew(t, phi, img) |
| 87 | keypoints, descrs = detector.detectAndCompute(timg, tmask) |
| 88 | for kp in keypoints: |
| 89 | x, y = kp.pt |
| 90 | kp.pt = tuple( np.dot(Ai, (x, y, 1)) ) |
| 91 | if descrs is None: |
| 92 | descrs = [] |
| 93 | return keypoints, descrs |
| 94 | |
| 95 | keypoints, descrs = [], [] |
| 96 | if pool is None: |
| 97 | ires = it.imap(f, params) |
| 98 | else: |
| 99 | ires = pool.imap(f, params) |
| 100 | |
| 101 | for i, (k, d) in enumerate(ires): |
| 102 | print('affine sampling: %d / %d\r' % (i+1, len(params)), end='') |
| 103 | keypoints.extend(k) |
| 104 | descrs.extend(d) |
| 105 | |
| 106 | print() |
| 107 | return keypoints, np.array(descrs) |
| 108 | |
| 109 | if __name__ == '__main__': |
| 110 | print(__doc__) |