10
10
11
11
class ContactArea :
12
12
def __init__ (
13
- self , base = None , draw_poly = True , contour_threshold = 100 , * args , ** kwargs
13
+ self , base = None , draw_poly = True , contour_threshold = 100 ,real_time = False , * args , ** kwargs
14
14
):
15
15
self .base = base
16
16
self .draw_poly = draw_poly
17
17
self .contour_threshold = contour_threshold
18
+ self .real_time = real_time
18
19
19
20
def __call__ (self , target , base = None ):
20
21
base = self .base if base is None else base
@@ -23,13 +24,18 @@ def __call__(self, target, base=None):
23
24
diff = self ._diff (target , base )
24
25
diff = self ._smooth (diff )
25
26
contours = self ._contours (diff )
26
- (
27
- poly ,
28
- major_axis ,
29
- major_axis_end ,
30
- minor_axis ,
31
- minor_axis_end ,
32
- ) = self ._compute_contact_area (contours , self .contour_threshold )
27
+ if self ._compute_contact_area (contours , self .contour_threshold ) == None and self .real_time == False :
28
+ raise Exception ("No contact area detected." )
29
+ if self ._compute_contact_area (contours , self .contour_threshold ) == None and self .real_time == True :
30
+ return None
31
+ else :
32
+ (
33
+ poly ,
34
+ major_axis ,
35
+ major_axis_end ,
36
+ minor_axis ,
37
+ minor_axis_end ,
38
+ ) = self ._compute_contact_area (contours , self .contour_threshold )
33
39
if self .draw_poly :
34
40
self ._draw_major_minor (
35
41
target , poly , major_axis , major_axis_end , minor_axis , minor_axis_end
@@ -104,4 +110,4 @@ def _compute_contact_area(self, contours, contour_threshold):
104
110
)
105
111
major_axis_end = 2 * center - major_axis
106
112
minor_axis_end = 2 * center - minor_axis
107
- return poly , major_axis , major_axis_end , minor_axis , minor_axis_end
113
+ return poly , major_axis , major_axis_end , minor_axis , minor_axis_end
0 commit comments