-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
84 lines (64 loc) · 2.2 KB
/
Copy pathutils.py
File metadata and controls
84 lines (64 loc) · 2.2 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import cv2
import logging
l = logging.getLogger('utils')
class Rect ( object ):
def __init__( self, ncols, nrows, center):
self.incols = ncols
self.inrows = nrows
self.topleft = Point(center.col - (self.incols / 2), center.row - (self.inrows / 2)) #center is a point
self.bottomright = Point(center.col + (self.incols / 2), center.row + (self.inrows / 2)) #center is a point
self.rectSize = (ncols, nrows)
self.center = center
def update ( self, center):
self.topleft.update(center.col - (self.incols / 2), center.row - (self.inrows / 2)) #center is a point
self.bottomright.update(center.col + (self.incols / 2), center.row + (self.inrows / 2))
self.center = center
##print self.center
@property
def right ( self ):
return self.bottomright.col
@property
def left ( self ):
return self.topleft.col
@property
def top ( self ):
return self.topleft.row
@property
def bottom ( self ):
return self.bottomright.row
@property
def ncols (self) :
return self.incols
@property
def nrows (self):
return self.inrows
def draw(self, img, color):
if self.topleft is None or self.bottomright is None:
return
cv2.rectangle( img, self.topleft.gimme(), self.bottomright.gimme(), color)
class Point ( object ):
def __init__( self, col, row):
self.icol = col
self.irow = row
def add (self, toAddCol,toAddRow):
outcol = self.icol + toAddCol
outrow = self.irow + toAddRow
newPoint = Point(outcol, outrow)
return newPoint
def update ( self, col, row):
self.icol = col
self.irow = row
def gimme ( self ):
return (int(self.icol), int(self.irow))
def __str__( self ):
return 'col: %d\trow: %d' % ( self.icol, self.irow)
@property
def row(self):
return self.irow
@property
def col(self):
return self.icol
def draw ( self, img, color ):
if self.icol is None or self.irow is None:
return
cv2.circle( img, (int(self.icol), int(self.irow)), 3 , color, -1 )