本文整理汇总了Python中SimpleCV.ImageClass.Image.getNumpy方法的典型用法代码示例。如果您正苦于以下问题:Python Image.getNumpy方法的具体用法?Python Image.getNumpy怎么用?Python Image.getNumpy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.ImageClass.Image
的用法示例。
在下文中一共展示了Image.getNumpy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RunningSegmentation
# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import getNumpy [as 别名]
class RunningSegmentation(SegmentationBase):
"""
RunningSegmentation performs segmentation using a running background model.
This model uses an accumulator which performs a running average of previous frames
where:
accumulator = ((1-alpha)input_image)+((alpha)accumulator)
"""
mError = False
mAlpha = 0.1
mThresh = 10
mModelImg = None
mDiffImg = None
mCurrImg = None
mBlobMaker = None
mGrayOnly = True
mReady = False
def __init__(self, alpha=0.7, thresh=(20,20,20)):
"""
Create an running background difference.
alpha - the update weighting where:
accumulator = ((1-alpha)input_image)+((alpha)accumulator)
threshold - the foreground background difference threshold.
"""
self.mError = False
self.mReady = False
self.mAlpha = alpha
self.mThresh = thresh
self.mModelImg = None
self.mDiffImg = None
self.mColorImg = None
self.mBlobMaker = BlobMaker()
def addImage(self, img):
"""
Add a single image to the segmentation algorithm
"""
if( img is None ):
return
self.mColorImg = img
if( self.mModelImg == None ):
self.mModelImg = Image(np.zeros((img.height, img.width, 3)).astype(np.float32))
self.mDiffImg = Image(np.zeros((img.height, img.width, 3)).astype(np.float32))
else:
# do the difference
self.mDiffImg = Image(cv2.absdiff(self.mModelImg.getNumpy(), self.mDiffImg.getNumpy()))
#update the model
npimg = np.zeros((img.height, img.width, 3)).astype(np.float32)
npimg = self.mModelImg.getFPNumpy()
cv2.accumulateWeighted(img.getFPNumpy(), npimg, self.mAlpha)
print npimg
self.mModelImg = Image(npimg)
#cv.RunningAvg(img.getFPMatrix(),self.mModelImg.getBitmap(),self.mAlpha)
self.mReady = True
return
def isReady(self):
"""
Returns true if the camera has a segmented image ready.
"""
return self.mReady
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.mModelImg = None
self.mDiffImg = None
def getRawImage(self):
"""
Return the segmented image with white representing the foreground
and black the background.
"""
return self._floatToInt(self.mDiffImg)
def getSegmentedImage(self, whiteFG=True):
"""
Return the segmented image with white representing the foreground
#.........这里部分代码省略.........
示例2: DFT
# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import getNumpy [as 别名]
#.........这里部分代码省略.........
warnings.warn("Empty Filter. Returning the image.")
return image
w, h = image.size()
if grayscale:
image = image.toGray()
fltImg = self._image
if fltImg.size() != image.size():
fltImg = fltImg.resize(w, h)
filteredImage = image.applyDFTFilter(fltImg)
return filteredImage
def getImage(self):
"""
**SUMMARY**
Get the SimpleCV Image of the filter
**RETURNS**
Image of the filter.
**EXAMPLE**
>>> notch = DFT.createNotchFilter(dia1=200, cen=(200, 200),
size=(512, 512), type="highpass")
>>> notch.getImage().show()
"""
if isinstance(self._image, type(None)):
if isinstance(self._numpy, type(None)):
warnings.warn("Filter doesn't contain any image")
self._image = Image(self._numpy)
return self._image
def getNumpy(self):
"""
**SUMMARY**
Get the numpy array of the filter
**RETURNS**
numpy array of the filter.
**EXAMPLE**
>>> notch = DFT.createNotchFilter(dia1=200, cen=(200, 200),
size=(512, 512), type="highpass")
>>> notch.getNumpy()
"""
if isinstance(self._numpy, type(None)):
if isinstance(self._image, type(None)):
warnings.warn("Filter doesn't contain any image")
self._numpy = self._image.getNumpy()
return self._numpy
def getOrder(self):
"""
**SUMMARY**
Get order of the butterworth filter
**RETURNS**
order of the butterworth filter
**EXAMPLE**