本文整理汇总了Python中panda3d.core.PNMImage.getNumPixels方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.getNumPixels方法的具体用法?Python PNMImage.getNumPixels怎么用?Python PNMImage.getNumPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.getNumPixels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTotalClickableArea
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getNumPixels [as 别名]
def getTotalClickableArea(self):
'''Compute the total clickable area, and compute its percentage relative to the image total size'''
### RENDERING CLICKABLE AREA
# Prepare the rendering of the clickable area
self.renderClickableArea()
# Render the frame
self.base.graphicsEngine.renderFrame()
### FETCHING THE RENDERED IMAGE
# Prepare the variable that will store the frame image (in a PNMImage class, this is NOT a file format, but a convenient image manipulation class offered by Panda3D)
screenshot = PNMImage()
# Set display region to the default
dr = base.camNode.getDisplayRegion(0)
# Store the rendered frame into the variable screenshot
dr.getScreenshot(screenshot)
### COMPUTE THE CLICKABLE AREA PERCENTAGE
# Prepare an histogram object
hist = PNMImage().Histogram()
# Compute the histogram
screenshot.makeHistogram(hist)
# Get the number of white opaque pixels (the clickable area)
totalClickableArea = hist.getCount(PNMImageHeader.PixelSpec(255,255,255, 255))
# Get the percentage of clickable area relative to the total image size
totalClickableAreaPercentage = float(totalClickableArea) * 100 / (screenshot.getReadXSize() * screenshot.getReadYSize())
if self.debug:
print("Total unique intensity pixels: %f" % hist.getNumPixels())
print("Total clickable area: %f" % totalClickableArea)
totalClickableAreaSqrt = sqrt(float(totalClickableArea))
print("Total clickable area sqrt: %f" % totalClickableAreaSqrt)
print("Size of image X*Y: %f * %f" %(screenshot.getReadXSize(), screenshot.getReadYSize()))
print("Total clickable area percentage: %f" % totalClickableAreaPercentage)
blackarea = hist.getCount(PNMImageHeader.PixelSpec(0,0,0, 255))
print("Total black area: %f" % blackarea)
print("Total black area percentage: %f" % (float(blackarea) * 100 / (screenshot.getReadXSize() * screenshot.getReadYSize())) )
return totalClickableAreaPercentage