-
Notifications
You must be signed in to change notification settings - Fork 25
/
tagDetection.py
42 lines (37 loc) · 963 Bytes
/
tagDetection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import cv2
class TagDetection(object):
def __init__(self):
self.good = False
self.obsCode = -1
self.matchCode = -1
self.id = -1
self.hammingDistance = -1
self.rotation = -1
self.points = None
self.homography = None
def addHomography(self):
"""
find homography
"""
self._recomputeHomography()
def addPoint(self,points):
"""
add quad`points to detection
:param points: quad`s points
"""
self.points = points
def _recomputeHomography(self):
"""
find Homography
:return: Homography
"""
src = np.array([
[-1, -1],
[1, -1],
[1, 1],
[-1, 1],
]).reshape(-1,1,2)
dst = np.array(self.points)
retval,mark = cv2.findHomography(np.array(src),np.array(dst))
self.homography = retval