当前位置: 首页>>代码示例>>Python>>正文


Python PNMImage.getNumPixels方法代码示例

本文整理汇总了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
开发者ID:lrq3000,项目名称:waCaptcha,代码行数:41,代码来源:worldgenerator.py


注:本文中的panda3d.core.PNMImage.getNumPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。