forked from jwarshaw/RaspberryDrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyzeblob.py
73 lines (53 loc) · 2.61 KB
/
analyzeblob.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
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
import SimpleCV
import cv2
import time
class AnalyzeBlob(object):
def __init__(self,img,blob):
self.vertical_boundary = 0.7
self.width_boundary = 0.4
self.img = img
self.blob = blob
self.angle_to_turn = 40
def isBlobBlocking(self):
if (self.__heightBelowThreshold() and self.__widthSufficientToBlock()):
return True
def isBlobDetectedOnLeft(self):
if (self.__anglingFromLeft() and self.__largeObjectStartingNearLeft()):
return True
if (self.__nearLineOnLeft()):
return True
if (self.__veryNearBlobOnLeft()):
return True
def isBlobDetectedOnRight(self):
if (self.__anglingFromRight() and self.__largeObjectStartingNearRight()):
return True
if self.__nearLineOnRight():
return True
if self.__veryNearBlobOnRight():
return True
def __nearLineOnRight(self):
return (self.blob.height() > self.img.size()[1] * 0.90) and (self.blob.minX() > self.img.size()[0] * 0.6)
def __nearLineOnLeft(self):
return (self.blob.height() > self.img.size()[1] * 0.90) and (self.blob.maxX() < self.img.size()[0] * 0.4)
def __veryNearBlobOnRight(self):
return (self.blob.height() > self.img.size()[1] * 0.40) and (self.blob.minX() > self.img.size()[0] * 0.5) and (self.blob.maxY() > self.img.size()[0] * 0.8)
def __veryNearBlobOnLeft(self):
return (self.blob.height() > self.img.size()[1] * 0.40) and (self.blob.maxX() < self.img.size()[0] * 0.5) and (self.blob.height() > self.img.size()[0] * 0.8)
def __anglingFromRight(self):
return self.blob.angle() < self.angle_to_turn
def __largeObjectStartingNearRight(self):
return (self.blob.maxX() > self.img.size()[0] * 0.80) and (self.blob.width() > self.img.size()[0] * 0.5) and (self.blob.maxY() < self.img.size()[1] * 0.8)
def isPocketOnRight(self):
return (self.blob.width() > self.img.size()[0] * 0.8 ) and (self.blob.height() > self.img.size()[0] * 0.8) and (self.blob.maxY() > self.img.size()[1] * 0.5)
def isPocketOnLeft(self):
return (self.blob.width() > self.img.size()[0] * 0.8 ) and (self.blob.height() > self.img.size()[0] * 0.8) and (self.blob.maxY() < self.img.size()[1] * 0.5)
def isBlobBlockingMoreRight(self):
return self.blob.angle() > 0
def __anglingFromLeft(self):
return self.blob.angle() > -1* self.angle_to_turn
def __largeObjectStartingNearLeft(self):
return (self.blob.minX() < self.img.size()[0] * 0.20) and (self.blob.width() > self.img.size()[0] * 0.5) and (self.blob.maxY() > self.img.size()[1] * 0.2)
def __heightBelowThreshold(self):
return self.blob.maxY() > self.img.size()[1] * self.vertical_boundary
def __widthSufficientToBlock(self):
return self.blob.width() > self.img.size()[0] * self.width_boundary