(self, frame, rect)
| 57 | |
| 58 | class MOSSE: |
| 59 | def __init__(self, frame, rect): |
| 60 | x1, y1, x2, y2 = rect |
| 61 | w, h = map(cv2.getOptimalDFTSize, [x2-x1, y2-y1]) |
| 62 | x1, y1 = (x1+x2-w)//2, (y1+y2-h)//2 |
| 63 | self.pos = x, y = x1+0.5*(w-1), y1+0.5*(h-1) |
| 64 | self.size = w, h |
| 65 | img = cv2.getRectSubPix(frame, (w, h), (x, y)) |
| 66 | |
| 67 | self.win = cv2.createHanningWindow((w, h), cv2.CV_32F) |
| 68 | g = np.zeros((h, w), np.float32) |
| 69 | g[h//2, w//2] = 1 |
| 70 | g = cv2.GaussianBlur(g, (-1, -1), 2.0) |
| 71 | g /= g.max() |
| 72 | |
| 73 | self.G = cv2.dft(g, flags=cv2.DFT_COMPLEX_OUTPUT) |
| 74 | self.H1 = np.zeros_like(self.G) |
| 75 | self.H2 = np.zeros_like(self.G) |
| 76 | for i in xrange(128): |
| 77 | a = self.preprocess(rnd_warp(img)) |
| 78 | A = cv2.dft(a, flags=cv2.DFT_COMPLEX_OUTPUT) |
| 79 | self.H1 += cv2.mulSpectrums(self.G, A, 0, conjB=True) |
| 80 | self.H2 += cv2.mulSpectrums( A, A, 0, conjB=True) |
| 81 | self.update_kernel() |
| 82 | self.update(frame) |
| 83 | |
| 84 | def update(self, frame, rate = 0.125): |
| 85 | (x, y), (w, h) = self.pos, self.size |
nothing calls this directly
no test coverage detected