forked from jwarshaw/RaspberryDrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyzeimage.py
92 lines (84 loc) · 2.64 KB
/
analyzeimage.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import SimpleCV
import cv2
import time
from analyzeblob import *
from car_maneuvers import *
from PIL import Image
class AnalyzeImage(object):
def __init__(self, image_path,connection):
self.default_command = "stop"
self.scvImg = SimpleCV.Image(image_path)
#adding in stop sign logic to check if speed slows down.
self.reds = self.scvImg.hueDistance(color=SimpleCV.Color.RED)
self.red_stretched_image = self.reds.stretch(20,21)
self.red_inverted_image = self.red_stretched_image.invert()
self.red_blobs = self.red_inverted_image.findBlobs(minsize=4500, maxsize=10000)
#directional blob logic
self.segmented_black_white = self.scvImg.stretch(180,181)
self.black_white_blobs = self.segmented_black_white.findBlobs(minsize=100)
self.car = CarManeuvers(connection)
def stopSign(self):
if ((self.red_blobs) and (len(self.red_blobs) > 0)):
return True
else:
return False
def runBlobFinder(self):
if self.stopSign():
print "STOP SIGN"
time.sleep(4)
return
if ((self.black_white_blobs) and (len(self.black_white_blobs) > 0)):
self.analyzeBlobs()
else:
self.car.forward()
# print x
# print blob
def analyzeBlobs(self):
blobs = self.scvImg.findBlobs(minsize = 100)
# if blobs:
# for blob in blobs:
# if blob.area() > 100:
# blob.draw(color=(128,0,0))
# self.scvImg.show()
# self.scvImg.show()
# time.sleep(2)
#check if blocked
for blob in self.black_white_blobs:
print blob
analyzed_blob = AnalyzeBlob(self.scvImg,blob)
if analyzed_blob.isBlobBlocking():
print "Blob blocks path"
if analyzed_blob.isPocketOnLeft():
print "Pocket Left"
self.car.wheels_left_back_up()
self.car.right()
elif analyzed_blob.isPocketOnRight():
print "Pocket right"
self.car.wheels_right_back_up()
self.car.left()
elif analyzed_blob.isBlobBlockingMoreRight():
print "On Right"
self.car.wheels_right_back_up()
else:
print "On Left"
self.car.wheels_left_back_up()
return
elif analyzed_blob.isBlobDetectedOnLeft():
print "Small blob on left"
self.car.right()
return
elif analyzed_blob.isBlobDetectedOnRight():
print "Small blob on right"
# if analyzed_blob.blockedOnRight():
self.car.left()
return
print "No Blobs in way"
#otherwise go forward
self.car.forward()
# detect blobs
# if blobs
# check left and check rightt
# is blocking?
# back up
# else
# turn (in correct direction)