pyfrp_idx_module.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:PyFRAP 作者: alexblaessle 项目源码 文件源码
def getPolyIdxImg(corners,res,debug=False):

    """Returns all indices of image that lie within given polygon.

    Args:
        corners (list): List of (x,y)-coordinates of corners.
        res (int): Resolution of image (e.g. 512).

    Keyword Args:
        debug (bool): Print debugging messages.

    Returns:
        tuple: Tuple containing:

            * indX (list): List of indices inside polygon in x-direction.
            * indY (list): List of indices inside polygon in y-direction.

    """

    #Convert to np array if necessary
    corners=np.asarray(corners)

    #Define polygonial patch
    poly = ptc.Polygon(corners,edgecolor='r',facecolor=(1,0,0,.2),)

    #Create grid
    x_int=np.arange(1,res+1,1)
    y_int=np.arange(1,res+1,1)
    g = np.meshgrid(x_int, y_int)

    #Zip them into coordinate tuples
    coords = list(zip(*(c.flat for c in g)))

    #Check which point is inside
    pts = np.vstack([p for p in coords if poly.contains_point(p, radius=0)])

    indX,indY= pts[0,:],pts[1,:]

    return indX,indY
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号