forked from sightmachine/SimpleCV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorSegmentation.py
More file actions
99 lines (82 loc) · 2.63 KB
/
Copy pathColorSegmentation.py
File metadata and controls
99 lines (82 loc) · 2.63 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from SimpleCV.base import *
from SimpleCV.Features import Feature, FeatureSet, BlobMaker
from SimpleCV.ColorModel import ColorModel
from SimpleCV.Color import Color
from SimpleCV.ImageClass import Image
from SimpleCV.Segmentation.SegmentationBase import SegmentationBase
class ColorSegmentation(SegmentationBase):
"""
Perform color segmentation based on a color model or color provided. This class
uses ColorModel.py to create a color model.
"""
mColorModel = []
mError = False
mCurImg = []
mTruthImg = []
mBlobMaker = []
def __init__(self):
self.mColorModel = ColorModel()
self.mError = False
self.mCurImg = Image()
self.mTruthImg = Image()
self.mBlobMaker = BlobMaker()
def addImage(self, img):
"""
Add a single image to the segmentation algorithm
"""
self.mTruthImg = img
self.mCurImg = self.mColorModel.threshold(img)
return
def isReady(self):
"""
Returns true if the camera has a segmented image ready.
"""
return True;
def isError(self):
"""
Returns true if the segmentation system has detected an error.
Eventually we'll consruct a syntax of errors so this becomes
more expressive
"""
return self.mError #need to make a generic error checker
def resetError(self):
"""
Clear the previous error.
"""
self.mError = false
return
def reset(self):
"""
Perform a reset of the segmentation systems underlying data.
"""
self.mColorModel.reset()
def getRawImage(self):
"""
Return the segmented image with white representing the foreground
and black the background.
"""
return self.mCurImg
def getSegmentedImage(self, whiteFG=True):
"""
Return the segmented image with white representing the foreground
and black the background.
"""
return self.mCurImg
def getSegmentedBlobs(self):
"""
return the segmented blobs from the fg/bg image
"""
return self.mBlobMaker.extractFromBinary(self.mCurImg,self.mTruthImg)
# The following are class specific methods
def addToModel(self, data):
self.mColorModel.add(data)
def subtractModel(self, data):
self.mColorModel.remove(data)
def __getstate__(self):
mydict = self.__dict__.copy()
self.mBlobMaker = None
del mydict['mBlobMaker']
return mydict
def __setstate__(self, mydict):
self.__dict__ = mydict
self.mBlobMaker = BlobMaker()