本文整理汇总了Python中SimpleCV.ImageClass.Image.set_colorkey方法的典型用法代码示例。如果您正苦于以下问题:Python Image.set_colorkey方法的具体用法?Python Image.set_colorkey怎么用?Python Image.set_colorkey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.ImageClass.Image
的用法示例。
在下文中一共展示了Image.set_colorkey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import set_colorkey [as 别名]
def draw(self, color = Color.GREEN, width = -1, alpha = -1, layer = None):
"""
**SUMMARY**
Draw the blob, in the given color, to the appropriate layer
By default, this draws the entire blob filled in, with holes. If you
provide a width, an outline of the exterior and interior contours is drawn.
**PARAMETERS**
* *color* -The color to render the blob as a color tuple.
* *alpha* - The alpha value of the rendered blob 0=transparent 255=opaque.
* *width* - The width of the drawn blob in pixels, if -1 then filled then the polygon is filled.
* *layer* - A source layer, if layer is not None, the blob is rendered to the layer versus the source image.
**RETURNS**
This method either works on the original source image, or on the drawing layer provided.
The method does not modify object itself.
**EXAMPLE**
>>> img = Image("lenna")
>>> blobs = img.findBlobs()
>>> blobs[-2].draw(color=Color.PUCE,width=-1,alpha=128)
>>> img.show()
"""
if not layer:
layer = self.image.dl()
if width == -1:
#copy the mask into 3 channels and multiply by the appropriate color
maskred = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 1)
maskgrn = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 1)
maskblu = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 1)
maskbit = cv.CreateImage(cv.GetSize(self.mMask._getGrayscaleBitmap()), cv.IPL_DEPTH_8U, 3)
cv.ConvertScale(self.mMask._getGrayscaleBitmap(), maskred, color[0] / 255.0)
cv.ConvertScale(self.mMask._getGrayscaleBitmap(), maskgrn, color[1] / 255.0)
cv.ConvertScale(self.mMask._getGrayscaleBitmap(), maskblu, color[2] / 255.0)
cv.Merge(maskblu, maskgrn, maskred, None, maskbit)
masksurface = Image(maskbit).getPGSurface()
masksurface.set_colorkey(Color.BLACK)
if alpha != -1:
masksurface.set_alpha(alpha)
layer._mSurface.blit(masksurface, self.topLeftCorner()) #KAT HERE
else:
self.drawOutline(color, alpha, width, layer)
self.drawHoles(color, alpha, width, layer)
示例2: draw
# 需要导入模块: from SimpleCV.ImageClass import Image [as 别名]
# 或者: from SimpleCV.ImageClass.Image import set_colorkey [as 别名]
def draw(self, color = Color.GREEN, alpha=-1, width=-1, layer=None):
"""
Draw the blob, in the given color, to the appropriate layer
By default, this draws the entire blob filled in, with holes. If you
provide a width, an outline of the exterior and interior contours is drawn.
color = The color to render the blob.
alpha = The alpha value of the rendered blob.
width = The width of the drawn blob in pixels, if -1 then filled then the polygon is filled.
layer = if layer is not None, the blob is rendered to the layer versus the source image.
Parameters:
color - Color object or Color tuple
alpha - Int
width - Int
layer - DrawingLayer
"""
if not layer:
layer = self.image.dl()
if width == -1:
#copy the mask into 3 channels and multiply by the appropriate color
maskred = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 1)
maskgrn = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 1)
maskblu = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 1)
maskbit = cv.CreateImage(cv.GetSize(self.mMask), cv.IPL_DEPTH_8U, 3)
cv.ConvertScale(self.mMask, maskred, color[0] / 255.0)
cv.ConvertScale(self.mMask, maskgrn, color[1] / 255.0)
cv.ConvertScale(self.mMask, maskblu, color[2] / 255.0)
cv.Merge(maskblu, maskgrn, maskred, None, maskbit)
masksurface = Image(maskbit).getPGSurface()
masksurface.set_colorkey(Color.BLACK)
if alpha != -1:
masksurface.set_alpha(alpha)
layer._mSurface.blit(masksurface, self.points[0])
else:
self.drawOutline(color, alpha, width, layer)
self.drawHoles(color, alpha, width, layer)