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


Python Image.getGrayNumpy方法代码示例

本文整理汇总了Python中SimpleCV.Image.getGrayNumpy方法的典型用法代码示例。如果您正苦于以下问题:Python Image.getGrayNumpy方法的具体用法?Python Image.getGrayNumpy怎么用?Python Image.getGrayNumpy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleCV.Image的用法示例。


在下文中一共展示了Image.getGrayNumpy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query_blob

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import getGrayNumpy [as 别名]
def query_blob(id):
    blob = Image("static\\img\\%d.jpg" % id).crop(
        int(request.form["x"]), int(request.form["y"]), int(request.form["width"]), int(request.form["height"])
    )
    if blob and "SK_MODEL" in app.config:
        if blob.height > blob.width:
            blob = blob.resize(h=app.config["PATCH_SIZE"])
        else:
            blob = blob.resize(w=app.config["PATCH_SIZE"])
        blob = blob.embiggen((app.config["PATCH_SIZE"], app.config["PATCH_SIZE"]))
        np_img = blob.getGrayNumpy().transpose().reshape(-1)
        pred = labels.inverse_transform(sk_model.predict(np_img))[0]
        return jsonify(prediction=pred)
    else:
        return jsonify(prediction="")
开发者ID:rolisz,项目名称:image_annotator,代码行数:17,代码来源:flask_annotator.py

示例2: parse_frame

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import getGrayNumpy [as 别名]
def parse_frame(img):
    """
    Parses a SimpleCV image object of a frame from Super Hexagon.
    Returns a ParsedFrame object containing selected features.
    """

    img

    # helper image size variables
    w,h = img.size()
    midx,midy = w/2,h/2

    # Create normalized images for targeting objects in the foreground or background.
    # (This normalization is handy since Super Hexagon's colors are inverted for some parts of the game)
    # fg_img = foreground image (bright walls, black when binarized)
    # bg_img = background image (bright space, black when binarized)
    fg_img = img
    if sum(img.binarize().getPixel(midx,midy)) == 0:
        fg_img = img.invert()
    bg_img = fg_img.invert()

    # We need to close any gaps around the center wall so we can detect its containing blob.
    # The gaps are resulting artifacts from video encoding.
    # The 'erode' function does this by expanding the dark parts of the image.
    bimg = bg_img.binarize()
    bimg = black_out_GUI(bimg)

    blobs = bimg.findBlobs()
    cursor_blob = get_cursor_blob(blobs, h, midx, midy)

    if cursor_blob:
        cursor_point = map(int, cursor_blob.centroid())
        cursor_r, cursor_angle = cart_to_polar(cursor_point[0] - midx, midy - cursor_point[1])

        cursor_angle = int(cursor_angle * 360/ (2 * pi))
        cursor_angle = 180 - cursor_angle
        if cursor_angle < 0:
            a += 360

        bimg = black_out_center(bimg, cursor_r).applyLayers()
        arr = bimg.resize(100).getGrayNumpy() > 100
        rot_arr = arr_to_polar(arr)
        rot_img = Image(PIL.Image.fromarray(np.uint8(np.transpose(rot_arr)*255))).dilate(iterations=3)
        rot_arr = rot_img.getGrayNumpy() > 100
        rot_img = rot_img.resize(400).flipVertical()
        return ParsedFrame(img, bimg, arr, rot_arr, rot_img, cursor_r, cursor_angle)
    else:
        return None
开发者ID:david-crespo,项目名称:py-super-hexagon,代码行数:50,代码来源:parse.py

示例3: getRotateBoxTest

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import getGrayNumpy [as 别名]
    def getRotateBoxTest(self):
        if not self._rotBoxTest:

            grayImg = self.image.toGray()
            diff = grayImg - self._boxFilter(grayImg, 35)

            result = [0]*18

            if not self.ellipse.error and self.ellipse.a > 0 and self.ellipse.b > 0:
                res = countInWindowEst(diff.threshold(6).getGrayNumpy(), 5)
                res = self._getRotatedAndScaledGalImg(Image(res))

                if res != None:
                    res = res.getGrayNumpy()

                    img = Image(res)
                    ellipse = self.ellipse
                    center = (img.width/2, img.height/2)
                    width = 10
                    diameter = int(max(ellipse.a, ellipse.b)*2)
                    mask = np.zeros_like(img.getGrayNumpy(), dtype=np.bool)
                    mask[center[0]-width/2:center[0]+width/2, center[1]-diameter/2:center[1]+diameter/2] = True
                    mask = Image(mask).threshold(0)

                    maxI = 0
                    maxThetaVal = 0

                    values = []

                    for i, theta in enumerate(xrange(-90, 90, 10)):
                        masked = (img & mask.rotate(theta, point=(img.width/2, img.height/2))).getGrayNumpy()
                        val = np.sum(masked)/float(img.width*img.height)
                        values.append(val)

                        if val > maxThetaVal:
                            maxThetaVal = val
                            maxI = i

                    result[0:len(values)-maxI] = values[maxI:]
                    result[len(values)-maxI:] = values[0:maxI]

            self._rotBoxTest = result

        return self._rotBoxTest
开发者ID:rmclaren,项目名称:Kaggle-GalaxyZoo,代码行数:46,代码来源:Galaxy.py


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