本文整理汇总了Python中SimpleCV.ImageClass.Image.binarize方法的典型用法代码示例。如果您正苦于以下问题:Python Image.binarize方法的具体用法?Python Image.binarize怎么用?Python Image.binarize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.ImageClass.Image
的用法示例。
在下文中一共展示了Image.binarize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DiffSegmentation
# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import binarize [as 别名]
#.........这里部分代码省略.........
def addImage(self, img):
"""
Add a single image to the segmentation algorithm
"""
if( img is None ):
return
if( self.mLastImg == None ):
if( self.mGrayOnlyMode ):
self.mLastImg = img.toGray()
self.mDiffImg = Image(self.mLastImg.getEmpty(1))
self.mCurrImg = None
else:
self.mLastImg = img
self.mDiffImg = Image(self.mLastImg.getEmpty(3))
self.mCurrImg = None
else:
if( self.mCurrImg is not None ): #catch the first step
self.mLastImg = self.mCurrImg
if( self.mGrayOnlyMode ):
self.mColorImg = img
self.mCurrImg = img.toGray()
else:
self.mColorImg = img
self.mCurrImg = img
self.mDiffImg = Image(cv2.absdiff(self.mCurrImg.getNumpy(), self.mLastImg.getNumpy()))
return
def isReady(self):
"""
Returns true if the camera has a segmented image ready.
"""
if( self.mDiffImg is None ):
return False
else:
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.mCurrImg = None
self.mLastImg = None
self.mDiffImg = None
def getRawImage(self):
"""
Return the segmented image with white representing the foreground
and black the background.
"""
return self.mDiffImg
def getSegmentedImage(self, whiteFG=True):
"""
Return the segmented image with white representing the foreground
and black the background.
"""
retVal = None
if( whiteFG ):
retVal = self.mDiffImg.binarize(thresh=self.mThreshold)
else:
retVal = self.mDiffImg.binarize(thresh=self.mThreshold).invert()
return retVal
def getSegmentedBlobs(self):
"""
return the segmented blobs from the fg/bg image
"""
retVal = []
if( self.mColorImg is not None and self.mDiffImg is not None ):
retVal = self.mBlobMaker.extractFromBinary(self.mDiffImg.binarize(thresh=self.mThreshold),self.mColorImg)
return retVal
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()